解锁

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

你可能感兴趣的:(MSSQL,object,kill,table,insert,null)