Created
March 17, 2021 08:55
-
-
Save boubkhaled/5466634d5180c25d2efb95fe10e352a4 to your computer and use it in GitHub Desktop.
kill SQL Server database processes
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 @id bigint | |
DECLARE @temp TABLE(id bigint) | |
INSERT @temp SELECT spid FROM master.dbo.sysprocesses WHERE dbid = db_id('Database_Name') | |
WHILE EXISTS(SELECT TOP 1 1 FROM @temp) | |
BEGIN | |
SET @id = (SELECT TOP 1 id FROM @temp) | |
EXEC('kill ' + @id) | |
DELETE @temp WHERE id = @id | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment