MSSQLSERVER数据库- 判断全局临时表是否存在

  写一下今天遇到的一个问题。

  今天因为一些作用域的问题,我使用了全局临时表,然后我在存储过程里使用了这么一段语句,想判断全局临时表是否存在,如果不存在,则将他DROP掉。

可是这段语句没用。

if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'[##temp]'))  
Begin  
    drop table ##temp;
End;

  这段语句在判断普通临时表的是可行的。

  可是用在全局临时表上竟然不行,然后在网上找了好久。终于找到了方法。如下:

if object_id('tempdb..##temp') is not null  
begin
    drop table ##temp
end;
else
begin
    print 'not za';
end;
原文地址:https://www.cnblogs.com/cxeye/p/3771147.html