Created
December 13, 2013 09:36
-
-
Save szunyog/7941990 to your computer and use it in GitHub Desktop.
Killing other processes connected to an MSSQL 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
declare @db_name varchar(100) = 'dbname'; | |
declare @kill_commands varchar(max) = ''; | |
select | |
@kill_commands=@kill_commands+'kill '+convert(varchar(5),spid)+';' | |
from master..sysprocesses | |
where | |
spid <> @@SPID -- avoid to kill the current process | |
and dbid=db_id(@db_name) | |
print 'Executing: ' + @kill_commands; | |
exec (@kill_commands); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment