Created
April 12, 2018 09:43
-
-
Save juanonsoftware/9d0709c2a5f88ed6c495ae7663d4a96d to your computer and use it in GitHub Desktop.
Kill blocking processes on a database
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
--- Kill blocked processes on a database | |
DECLARE @databasename nvarchar(50) | |
SET @databasename = N'Datbase_Name' | |
-- SET @databasename = DB_NAME() | |
DECLARE @Sql varchar(max) | |
SET @Sql = '' | |
SELECT @Sql = @Sql + 'Kill ' + Convert(varchar, SPId) + ';' | |
FROM master.dbo.sysprocesses | |
WHERE DBId = DB_ID(@databasename) AND SPId <> @@spid | |
and spid IN (SELECT blocked FROM master.dbo.sysprocesses) | |
--You can see the kill Processes ID | |
SELECT @Sql | |
--Kill the Processes | |
EXEC(@Sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment