Skip to content

Instantly share code, notes, and snippets.

@blanchak
Created November 2, 2011 14:02
Show Gist options
  • Save blanchak/1333710 to your computer and use it in GitHub Desktop.
Save blanchak/1333710 to your computer and use it in GitHub Desktop.
Kill database running processes in SQL Server
USE master
print 'Kill running processes'
DECLARE @SQL VARCHAR(MAX)
SET @SQL = ''
SELECT @SQL = @SQL + 'Kill ' + CONVERT(VARCHAR, SPId) + ';'
FROM MASTER..SysProcesses
WHERE DBId = DB_ID('YOUR_DATABASE') AND SPId <> @@SPId
print @SQL
EXEC(@SQL)
GO
@sebascomeau
Copy link

Nice job buddy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment