Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I detect a local temp table

Dom
Guest
 
Posts: n/a
#1: Nov 14 '08
I sometimes begin a script like this:

-------------------------------------------------------------
if exists (select * from sysobjects where name = 'T_Table') drop table
T_Table

select * into T_Table (etc)
-------------------------------------------------------------

How do I do this with a local temp table? I thought of this:

if exists (select * from sysobjects where name like '#Temp_%') drop
table #Temp

.... but that seems dangerous to me. Is there a better way?

Dom





Plamen Ratchev
Guest
 
Posts: n/a
#2: Nov 14 '08

re: How do I detect a local temp table


I normally use this approach which works well:

IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL
DROP TABLE #Temp;


--
Plamen Ratchev
http://www.SQLStudio.com
Closed Thread