[MSSQL]如何檢驗暫存資料表是否存在
發表於 : 2008年 11月 28日, 17:08
由於暫存資料表 (temp table) 使用很方便, 但有時要檢查是否存在, 來進一步刪除或是新增異動資料時, 則必須有效檢查其存在與否, 可以使用檢查 tempdb..#xxx 的 object_id 是否有值即可, 若是為 null 表示不存在!!
if object_id('tempdb..#aa') is not null
print 'exists'
else
print 'not exists'
if object_id('tempdb..#aa') is not null
print 'exists'
else
print 'not exists'