Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Loop to delete temporary tables

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-09-18 : 09:28:31
I used code below to delete one temporary table:

IF OBJECT_ID('tempdb..#T1') IS NOT NULL drop table #T1

How to code a loop to delete all temporary tables?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-18 : 10:03:13
declare @sql varchar(8000)
set @sql=''
select @sql=@sql+' drop table '+name from tempdb..sysobjects where xtype='u'
exec(@sql)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -