/ Published in: SQL
Verify whether temporary table created is exists or not
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
--Create table USE Norhtwind GO CREATE TABLE #temp(id INT) --Check if it exists IF OBJECT_ID('tempdb..#temp') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --Another way to check with an undocumented optional second parameter IF OBJECT_ID('tempdb..#temp','u') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --Don't do this because this checks the local DB and will return does not exist IF OBJECT_ID('tempdb..#temp','local') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --unless you do something like this USE tempdb GO --Now it exists again IF OBJECT_ID('tempdb..#temp','local') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END