Kill all the current active connection in SQL Server database

There are times when you want to kill all the current active connections of your SQL Server database and you wish to run the database in the single user instance.

Here’s the query on how to do this.

use master
ALTER DATABASE <NameoftheDatabase> SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Once done with any changes , ensure that the MULTI_USER mode is enabled for the database.

ALTER DATABASE <NameoftheDatabase>  SET MULTI_USER

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

Dealing with the column names that looks like SQL Keywords in SQL Server
There are times when you might have a column names in your SQL Server database table that might look...
SQL Server's ISNULL() equivalent in PostgreSQL
SQL Server provides an function ISNULL if the value placed in the 2nd parameter if the first paramet...
WAITFOR TIME in SQL Server
If you want to pause the execution of the code block until a specific time is reached , you can try ...