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
GO
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
GO
在上面的基础上加游标