Search code examples
sql-server-2008database-deadlocks

How to kill/Terminate all running process on Sql Server 2008


After executing this query on master db ,it is giving me all running process on all databases, is there any query which will kill all process running on a database .

USE
Master
GO

SELECT
SPID,DBID FROM SYSPROCESSES
WHERE
DBID NOT IN (1,2,3,4) AND SPID >50 AND SPID<> @@spid   

Solution

  • If you want to force every other connection to disconnect, and you have suitable permissions, you can bounce the database in and out of single user mode:

    alter database current set single_user with rollback immediate;
    go
    alter database current set multi_user;
    go
    

    Any other connection to the same database will be terminated.