Skip to content

Instantly share code, notes, and snippets.

@bvanskiver
Created January 28, 2016 15:45
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 bvanskiver/d53cf5d92567f2e3c9b0 to your computer and use it in GitHub Desktop.
Save bvanskiver/d53cf5d92567f2e3c9b0 to your computer and use it in GitHub Desktop.
Kill all users 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