关于临时表的个人经验

临时表有两种,一种是全局的,用"##"开头,当前用同一帐号登录的所有会话可见,如:##temptable;
还有一种是局部,只用当前会话可见,用"#"开头,如:#temptable;
两种表其实是相当相像的;


/* making ##temp table*/
select * into ##temptable from table

/* making #temp table*/
select * into #temptable from table


/* drop ##temp table */
if exists(select * from tempdb.dbo.sysobjects where name='##temptable')
begin
drop table ##temptable
end

/* drop #temp table */
if object_id('tempdb..#temptable') is not null
begin
drop table #temptableA
end


注意:如果用exec (sqltring)方法建立的局部临时表,那是在sqltring外不可以见的
posted on 2005-11-04 10:06  microtea  阅读(286)  评论(0编辑  收藏  举报