Skip to content

Instantly share code, notes, and snippets.

@tompazourek
Created September 4, 2015 13:14
Show Gist options
  • Save tompazourek/6ccf9e6526e738c64a8e to your computer and use it in GitHub Desktop.
Save tompazourek/6ccf9e6526e738c64a8e to your computer and use it in GitHub Desktop.
USE [master]
DECLARE @dbname SYSNAME
SET @dbname = 'DATABASENAME'
DECLARE @spid INT
SELECT @spid = MIN([spid]) FROM [master].[dbo].[sysprocesses] WHERE [dbid] = DB_ID(@dbname)
WHILE @spid IS NOT NULL
BEGIN
EXECUTE ('KILL ' + @spid)
SELECT @spid = MIN(spid) FROM [master].[dbo].[sysprocesses] WHERE [dbid] = DB_ID(@dbname) AND [spid] > @spid
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment