declare @i int = 1
if (@i= 2)
Begin
declare @t table (value int)
insert into @t
select 1
select * from @t
end
else
select *from @t
---------------
declare @i int = 1
if (@i= 2)
Begin
create table #t(value int)
insert into #t
select 1
end
else
select *from #t
为什么表变量没有得到无效的对象名称?
最佳答案
T-SQL 中变量的范围不限于 block 。局部变量的范围是声明它的批处理。
有人要求声明仅在 block 内可见的变量,但 Microsoft 拒绝了。这是 link
关于sql - 表变量与临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45610648/