--在维护中经常需要将某一数据库所有进程都杀掉,手工杀有点太费事。写了一个存储过程
--usage:proc_kill ‘PSADBA‘
create proc proc_kill(@db varchar(24))
as
begin
declare @str varchar(max)= ‘‘
declare @msg varchar(max)=‘‘
begin try
if db_id(@db) is null
raiserror(‘%s database not exist.‘,0,1,@db) with nowait
select @[email protected]+‘kill ‘+cast(spid as varchar(4))+‘;‘ from sys.sysprocesses
where dbid=DB_ID(@db) and spid>=50
print @str
exec(@str)
end try
begin catch
set @msg = ERROR_MESSAGE()
raiserror(@msg,16,1)with nowait
end catch
end
时间: 2024-11-10 07:03:23