Skip to content

Instantly share code, notes, and snippets.

@bigsan
Created November 19, 2010 17:19
Show Gist options
  • Save bigsan/706810 to your computer and use it in GitHub Desktop.
Save bigsan/706810 to your computer and use it in GitHub Desktop.
SQL: Kill processes related to some database
DECLARE @dbName nvarchar(max), @sql nvarchar(max)
SELECT @dbName = N'__DBNAME__', @sql = N''
SELECT @sql = @sql + N'KILL ' + CONVERT(nvarchar(max), spid) + ';'
FROM master..sysprocesses
WHERE dbid = DB_ID(@dbName)
--EXEC sp_executesql @sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment