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

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

kishoremcp
Starting Member

India
39 Posts

Posted - 10/04/2013 :  10:21:16  Show Profile  Reply with Quote
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

India
52309 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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 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


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000