In development and testing environments we quite often have to drop databases and re-create them from scratch. It’s a little bit annoying when you need to right on click the database in SQL Management Studio, select Delete, and even put a tick on “Close existing connections” to be able to delete the database when it’s in use.
It’s more efficient to drop the database using a query. The query below will instantly rollback any running transactions and set database in a single user mode.
This allows to drop the database quickly and painlessly.