Technical Article

Kill Connections to Specific Database - Updated

,

Quick & Easy way to kill connections to specific database

USE [Master]
GO

DECLARE @DBNameVARCHAR(100)
DECLARE @SPIdVARCHAR(7000)
SELECT@DBName= 'DBAdmin'

SELECT@SPId = COALESCE(@SPId,'')+'KILL '+CAST(SPID AS VARCHAR)+'; '
FROMMaster..SysProcesses
WHEREDB_NAME(DBId) = @DBName

PRINT @SPId
EXEC(@SPId)
GO

Rate

3 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

3 (2)

You rated this post out of 5. Change rating