Kill Connections to Specific Database - Updated

,

Quick & Easy way to kill connections to specific database

USE [Master]
GO

DECLARE @DBName	VARCHAR(100)
DECLARE @SPId	VARCHAR(7000)
SELECT	@DBName	= 'DBAdmin'

SELECT	@SPId = COALESCE(@SPId,'')+'KILL '+CAST(SPID AS VARCHAR)+'; '
FROM	Master..SysProcesses
WHERE	DB_NAME(DBId) = @DBName
		
PRINT @SPId
EXEC(@SPId)
GO

Rate

3 (2)

Share

Share

Rate

3 (2)