How to drop a database gracefully
1. Check Active connections
Check Active connections by running the below command. If there are any active connections then you need to terminate those connections
USE master;
SELECT * FROM sys.sysprocesses WHERE dbid = DB_ID('TestDB');
2. Disconnect users
You need to disconnect users. If you run the below statement, it will set the database to single-user mode
USE master;
ALTER DATABASE TestDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
3. After doing this, try to drop the database by running the below command.
DROP DATABASE TestDB;
Comments
Post a Comment