How to delete a locked DB in MSSQL?

One of the problems I had is that I couldn’t delete a locked DB in the SQL Management Studio.

 Here is the code that is deleting the DB. Just change the MYDB with your db name.

USE master -- be sure that you're not on MYDB
ALTER DATABASE MYDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE MYDB;

You may also like...