Created
July 7, 2014 02:50
-
-
Save amigoavena/966205ea3458919c5516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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