SQL Server - quickly delete all tables
With most things in SQL Server it’s tempting to think you can script it. Because most of the time you can.
Recently, I had a requirement to quickly drop everything out of a database (but without actually just dropping the whole database.)
The best option I found, was:
- In the database tree view, find the container for the type of objects you want to delete (e.g., tables)
- Press F7 to open up the Object Explorer
- From here, select all the items you want to delete. Press delete.
- This opens up the standard ‘drop item' dialog, but with all those objects included.
- Hit OK
And boom, away it goes. You can repeat this for any database objects by navigating around the Object Explorer. If you wanted to script this, you’d need to (probably) start navigating the master database and get some cursors and whatnot going on.