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.
Author |
Topic |
kishoremcp
Starting Member
41 Posts |
Posted - 2013-10-04 : 10:21:16
|
hi,
I have around 20 temp tables in SQL Server.
How to I drop them all at a time.
Temp tables are named as #temp1, #temp2, ....#temp20...
Thanks in advance..
Regards Kishore |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-04 : 10:31:34
|
you dont need to drop them explicitly. They will automaticaly once connection terminates
If your attempt is to drop them within same connection you need to use something like
SELECT 'DROP TABLE ' + TABLE_NAME FROM tempdb.information_schema.tables where TABLE_NAME LIKE '#temp%'
then copy the result and paste on the same window and execute or add it to a variable and use dynamic sql to execute it
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-10-08 : 07:25:08
|
It is as simple as
Drop table #temp1, #temp2, .... , #temp20
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
|
|