mysql技术总结

来源:互联网 发布:制作婚礼照片软件 编辑:程序博客网 时间:2024/05/22 06:23
 创建全局临时表和局部临时表 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





0 0
原创粉丝点击