Monday, September 7, 2009

Drop/Remove/Delete all tables in a SQL Server database

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' "

This is the same in both SQL Server 2000 and SQL Server 2005

You have to execute the code a number of times or until no more tables remain in your database

No comments:

Post a Comment