我想知道为什么while循环中的表变量不像其他变量那样工作。表变量只创建一次,并在整个循环中使用,但其他变量每次循环增加时都会被初始化。
请查看以下代码以获取更多信息:
declare @tt int
set @tt =10
while @tt>0
begin
declare @temptable table(id int identity(1,1),sid bigint)
insert into @temptable
select @tt union all
select @tt + 1
select * from @temptable
--delete from @temptable
set @tt=@tt-1
end
这是个bug吗?