Link to home
Start Free TrialLog in
Avatar of Zolf
ZolfFlag for United Arab Emirates

asked on

Delete all tables

hello there,

how can i delete all the tables from my hosting sql server 2005 database.one way is to right clcik and select delete.but this is tds since i have more then 30 tables.thanks.

cheers
ZOlf
ASKER CERTIFIED SOLUTION
Avatar of MacNuttin
MacNuttin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
select 'drop table '+table_name
from information_schema
do you want to DELETE the data, or the complete table definition (DROP) ?
exec sp_msForEachTable 'DELETE FROM ?' 
resp: 
exec sp_msForEachTable 'DROP TABLE ?'

Open in new window

Hi there:

To drop all tables in a SQL Server 2005 database use :

sp_MSforeachtable command1 [,replacechar] [, command2] [,command3] [,whereand] [,precommand] [,postcommand

Example : exec sp_MSforeachtable "DROP TABLE ? PRINT '? dropped' " 

Best regards...
There are some simple queries you can use too...
I have a SQL2000 database here and with this I get a list of all my (user) tables.
select name from sysobjects where xtype = 'U'
Then with curser or text editor I basically issue
drop table tablename1
drop table tablename2
etc...