Here is a handy command to clear all tables on your (local) database.
- Select the Database in SQL Server Management Studio, and hit New Query
- Run the following command
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
That is good for dropping all tables. Most of the time, you’d like to delete all table data. Also, to overcome tables associations on constraints/keys, etc. Use the following in this case:
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' EXEC sp_MSForEachTable 'DELETE FROM ?' EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
Note: You cannot use TRUNCATE with above syntax!
Happy coding 🙂