Created
January 19, 2015 12:51
-
-
Save bvanskiver/8ca70ed3d544df251efe to your computer and use it in GitHub Desktop.
Kill all processes in specified database(s)
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 @spid int, @cnt int, @sql varchar(255) | |
select @spid = min(spid), @cnt = COUNT(*) | |
from sysprocesses p | |
inner join sysdatabases d on p.[dbid] = d.[dbid] | |
where d.name like '%Internal%' | |
print 'Killing ' + CAST(@cnt as varchar) + ' processes.' | |
while @spid is not null | |
begin | |
set @sql = 'KILL ' + CAST(@spid as varchar) | |
print @sql | |
exec (@sql) | |
select @spid = min(spid), @cnt = COUNT(*) | |
from sysprocesses p | |
inner join sysdatabases d on p.[dbid] = d.[dbid] | |
where d.name like '%Internal%' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment