Note: This article was originally published in 2011. Some steps, commands, or software versions may have changed. Check the current Microsoft documentation for the latest information.

Prerequisites

Before you begin, make sure you have:

  • SQL Server instance installed
  • SQL Server Management Studio (SSMS)
  • Appropriate database permissions

I’ve recently been working on a data migration and I constantly been needing to delete all the tables in the db and start over. After doing some research I came across this hidden stored procedure in SQL Server that allows you to delete each table in the database you are connected to. Use this extremely carefully as you can’t rollback this and if you connect to the wrong db you’re going to wipe all the data. try this EXEC sp_MSforeachtable @command1 = “DROP TABLE ?” You can also use the shell but I haven’t tried that EXEC xp_cmdshell ‘SQLCMD -U -P -Q ‘EXEC sp_MSforeachtable @command1 = “DROP TABLE ?” ’ ,no_output

Summary

You’ve successfully learned delete/drop all the tables from a sql server database. If you run into any issues, double-check the prerequisites and ensure your Microsoft environment is properly configured.