Skip to content

Instantly share code, notes, and snippets.

@boubkhaled
Created March 17, 2021 08:55
Show Gist options
  • Save boubkhaled/5466634d5180c25d2efb95fe10e352a4 to your computer and use it in GitHub Desktop.
Save boubkhaled/5466634d5180c25d2efb95fe10e352a4 to your computer and use it in GitHub Desktop.
kill SQL Server database processes
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