自动杀死死进程
CREATE PROCEDURE SP_AUTOKILLID AS
declare
@li_lockcnt integer,
@li_spid integer,
@ls_cmd char(50),
@ls_sql char(30)
select @li_lockcnt = count(*) from master..syslocks where type =258
if @li_lockcnt<1
return
else
begin
select @li_spid = spid from master..syslocks where type = 258
if @li_spid is null
return
else
begin
select @ls_cmd = cmd from master..sysprocesses where spid = @li_spid
if @ls_cmd = 'AWAITING COMMAND'
begin
select @ls_sql = 'KILL '+ltrim(str(@li_spid))
exec(@ls_sql)
end
end
end
create proc killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500)
declare @spid int
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status < >-1
begin
exec('kill '+rtrim(@spid))
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end