Can’t drop SQL database because it currently in use.

Can’t drop SQL database because it currently in use.

In the result box from the screenshot, we can see that there are some of the database can’t be deleted due to it’s currently in use.

A normal DROP database query will not working. Instead you can make SQL script like below:

USE master;
GO

IF DB_ID(N'DATABASE_NAME') IS NOT NULL
BEGIN
    ALTER DATABASE [DATABASE_NAME]
    SET SINGLE_USER
    WITH ROLLBACK IMMEDIATE;

    DROP DATABASE [DATABASE_NAME];
END
GO

WITH ROLLBACK IMMEDIATE will disconnect all active connection and will continue to DROP the database once all the active connection disconnected.

Be careful with the command since the command will drop your database entirely.

fariskmrdn Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *