In this post, I am sharing scripts to kill all your running processes or sessions of SQL Server.
DBA always set time of database maintenance activities, but sometime they find few running sessions so they require to close all connections of a SQL Server Database.
Before executing this script, please take care and verify all running connections and processes otherwise this script will harm to your data.
You require this type of script very occasionally, but I am sharing here because this is also one of the important script for SQL DBA.
How to find running sessions or processes in SQL Server?
Command to Kill particular session_id:
Change your database mode from multi-user to single-user:
Once you change the database mode from multi-user to single-user, SQL Server immediately stops all the connections of the database. No one can connect to that database.
The DBA can perform the maintenance activity and after that, they can again change the database mode from single-user to multi-user.
To set Single User:
1 ALTER DATABASE [Database_Name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
To set Multi User:
1 ALTER DATABASE [Database_Name] SET MULTI_USER WITH ROLLBACK IMMEDIATE