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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Drop temp tables
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

41 Posts

Posted - 10/04/2013 :  10:21:16  Show Profile  Reply with Quote

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..


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/04/2013 :  10:31:34  Show Profile  Reply with Quote
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
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 10/08/2013 :  07:25:08  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
It is as simple as

Drop table #temp1, #temp2, .... , #temp20


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000