Skip to content

Instantly share code, notes, and snippets.

@bvanskiver
Created January 19, 2015 12:51
Show Gist options
  • Save bvanskiver/8ca70ed3d544df251efe to your computer and use it in GitHub Desktop.
Save bvanskiver/8ca70ed3d544df251efe to your computer and use it in GitHub Desktop.
Kill all processes in specified database(s)
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