双鱼座的天蝎

导航

sql临时表与变量表

1)临时表存储在 tempdb 中,当不再使用时会自动删除

一般使用如下:

--创建临时表
select * into #temp from TABLE 

--使用临时表
select * from #temp

--删除临时表
drop table #temp

 

注意:临时表需要用#开头,##表示全局临时表

 

2)一般而言,变量表和普通变量一样存储在内存中;当变量表的数据量足够大时,与临时表一样存储在 tempdb 中

一般使用如下:

--声明表变量
declare @t table(UserID int);

--为表变量赋值
insert into @t from TABLE

--使用表变量
select * from @t

 

posted on 2019-09-06 13:25  双鱼座的天蝎  阅读(368)  评论(0编辑  收藏  举报