--临时表存在于系统数据库tempdb内
全局的临时表使用##即两个#号
例
--判断临时表是否存在
if (object_id('tempdb..##tempTable') is not null)
begin
print 1
drop table iweix.##tempTable
end
--创建临时表
create table iweix.##tempTable
(
id int primary key identity,
[name] nvarchar(100)
)
insert into ##tempTable ([name]) values('a')
insert into ##tempTable ([name]) values('b')
select * from ##tempTable
全局临时表一旦建立在其他查询时也可以使用里面的数据
局部临时表仅限于本次连接查询,在其他查询连接中无效使用单#号建立
例如
--判断临时表是否存在
if (object_id('tempdb..#tempTable') is not null)
begin
print 1
drop table iweix.#tempTable
end
--创建临时表
create table iweix.#tempTable
(
id int primary key identity,
[name] nvarchar(100)
)
insert into #tempTable ([name]) values('a')
insert into #tempTable ([name]) values('b')
select * from #tempTable
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22328375/viewspace-613255/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22328375/viewspace-613255/