How to drop everything in a MS SQL Database

When working with SQL data and lots of foreign keys, you may have the need to drop everything. Well I have just the right SQL statement for you. The following statement will drop everything the given database, including the following:

  • non-system stored procedures
  • views
  • functions
  • foreign key constraints
  • primary key constraints
  • tables

You can execute parts of the script on its own if you only want to drop a certain part.

Drop everything in a MSSQL database

The SQL script must be execute on the database level. Optionally you can add an USE ‘YOUR_DATABASE_NAME’ statement on the top.

Update 07.01.2019

I added the option to iterate over all schemas in the selected database and drop everything in every schema including the schema.