Skip to content

Instantly share code, notes, and snippets.

@szunyog
Created December 13, 2013 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szunyog/7941990 to your computer and use it in GitHub Desktop.
Save szunyog/7941990 to your computer and use it in GitHub Desktop.
Killing other processes connected to an MSSQL database.
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