Tuesday, June 18, 2019

Cannot drop database because it is currently in use

When we want to drop database from MS SQL server but it show below message

"Cannot drop database because it is currently in use"

Here I have written SQL script which will help us to delete a database which is currently used by some of the process, users, application etc. 

--Cannot drop database "demo" because it is currently in use.
USE master
GO
--Kick all users off of the database NOW
ALTER DATABASE DEMO SET SINGLE_USER WITH ROLLBACK IMMEDIATE

--Kick all but after 60 seconds
ALTER DATABASE DEMO SET SINGLE_USER WITH ROLLBACK AFTER 60 SECONDS

--restore connection to users
--ALTER DATABASE DEMO SET MULTI_USER

DROP DATABASE DEMO;


Hope it will help you to resolve your problem when you not able to delete the existing database.

Keep sharing keep learning. Thank you 

No comments:

Post a Comment