467,134 Members | 982 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,134 developers. It's quick & easy.

How do I detect a local temp table

Dom
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


Nov 14 '08 #1
  • viewed: 2930
Share:
1 Reply
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
Nov 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Beringer | last post: by
2 posts views Thread by chris.ciotti@gmail.com | last post: by
1 post views Thread by Matt Walker | last post: by
9 posts views Thread by Shilpa | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.