View Full Version : Asking exists


accessman2
11-28-2006, 08:38 AM
Hi,

if exists(select * from information_schema.tables where Table_Name = '##tbl')
drop table ##tbl

Can we use this statement to drop temporary table?

Because when I run it, it cannot delete the temporary table.

So, we cannot check the temporary table.

Please let me know, thanks.
Thanks.

SQL_Hell
11-29-2006, 04:53 AM
Temporary tables are dropped when the connection is dropped, so you should need to drop a temporary table, just close the connection

pdx_man
11-29-2006, 09:23 AM
Single # temp tables are dropped with the connection, double # (Global Temp Tables) are seen by all connections and stay alive until they are dropped. Both reside in the tempdb database.

if exists(select * from tempdb.dbo.sysobjects where Name Like '##tbl%')
drop table ##tbl