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
 General SQL Server Forums
 New to SQL Server Administration
 drop all the tables

Author  Topic 

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2010-11-03 : 13:39:15
Is there an easy way to drop all tables in a database from management studio. I am using SQL 2005

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-03 : 13:47:51
select 'drop table ' + TABLE_NAME +
from INFORMATION_SCHEMA.TABLES

Run the script and the output until there aren't any errors (FK issues).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2010-11-03 : 13:51:50
Another way is to use object explorer to right click the database and select tasks | generate sql script. then go through the options. you can de-select "include create" and select "include drop". The constraints will be handled accordingly.



Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-04 : 06:41:08
You can alos change truncate and delete table to drop table
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/truncate-all-tables-part-ii.aspx

Madhivanan

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

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-11-04 : 08:19:15
Yet another way:

exec sp_msforeachtable 'DROP TABLE ?'

As Tara mentioned you'll get errors if there are foreign keys, but multiple runs will drop them all.
Go to Top of Page
   

- Advertisement -