mysql技术总结

本文介绍了如何在SQL Server中创建全局和局部临时表,并提供了详细的代码示例。全局临时表使用##标识,可在整个会话期间被多个连接访问;局部临时表使用#标识,仅限于当前会话使用。
  创建全局临时表和局部临时表  2009-08-26 10:00:54

分类: Linux

--临时表存在于系统数据库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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值