create procedure sp_kill(@tbname varchar(100),@dbname varchar(100))
as
begin
declare @spid int
if OBJECT_ID('tempdb.dbo.#Kill') is not null
drop table #Kill
create table #Kill
(
[spid] int,
[dbid] int,
[ObjId] int,
[IndId] int,
[Type] varchar(50),
[Resource] varchar(50),
[Mode] varchar(20),
[Status] varchar(100)
)
INSERT INTO #Kill([spid],[dbid],[ObjId],[IndId],[Type],[Resource],[Mode],[Status])
exec sp_lock
while (select COUNT(*) from #Kill where ObjId=OBJECT_ID(@tbname) and dbid=DB_ID(@dbname))<>0
begin
set @spid=(
select top 1 spid
from #Kill
where ObjId=OBJECT_ID(@tbname) and dbid=DB_ID(@dbname)
)
exec('kill '+@spid)
end
end
go
解锁
最新推荐文章于 2025-02-02 16:55:44 发布