Skip to content

Instantly share code, notes, and snippets.

@amigoavena
Created July 7, 2014 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amigoavena/966205ea3458919c5516 to your computer and use it in GitHub Desktop.
Save amigoavena/966205ea3458919c5516 to your computer and use it in GitHub Desktop.
DECLARE UserCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT
spid
FROM
master.dbo.sysprocesses
WHERE DB_NAME(dbid) = 'dbname'--replace the dbname with your database
DECLARE @spid SMALLINT
DECLARE @SQLCommand VARCHAR(300)
OPEN UserCursor
FETCH NEXT FROM UserCursor INTO
@spid
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQLCommand = 'KILL ' + CAST(@spid AS VARCHAR)
EXECUTE(@SQLCommand)
FETCH NEXT FROM UserCursor INTO
@spid
END
CLOSE UserCursor
DEALLOCATE UserCursor
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment