Select * from tmpdb..sysobjects where name like '##t_zzf%'
if object_id('tempdb....##t_zzf') select '存在'
if exists(select * from tempdb..sysobjects where name='##temp') print 1 else print 2
不能这样用:应当这样:if exist(slect * from ##t_zzf) ... else
if exists(select * from tempdb..sysobjects where name='##temp') ... else ...
临时表: if object_id('tempdb..temptablename') is not null print 'temptable exist'游标: if CURSOR_STATUS('global','cursorname')=-3 and CURSOR_STATUS('local','cursorname')=-3 print 'not exist'
if object_id('tempdb....##t_zzf')
或都不管在不在都先用 Drop Table 将它除去
if object_id('tempdb..temptablename') is not null 存在 else 不在
if object_id('tempdb..##t_zzf from tcs') is not null 存在 else 不在
if object_id('tempdb..##t_zzf') is not null select '存在' else select '不存在'
select '存在'
print 1
else
print 2
...
else
...
else
...
if object_id('tempdb..temptablename') is not null
print 'temptable exist'游标:
if CURSOR_STATUS('global','cursorname')=-3 and CURSOR_STATUS('local','cursorname')=-3
print 'not exist'
存在
else
不在
if object_id('tempdb..##t_zzf from tcs') is not null
存在
else
不在
select '存在'
else
select '不存在'