死鎖查詢1

2021-05-27 08:23:03 字數 1387 閱讀 9416

create table #who(

spid int,

ecid int,

status nvarchar(50),

loginname nvarchar(50),

hostname nvarchar(50),

blk int,

dbname nvarchar(50),

cmd nvarchar(50))

create table #lock(

spid int,

dpid int,

objid int,

indld int,

type nvarchar(20),

resource nvarchar(50),

mode nvarchar(10),

status nvarchar(10)

)insert into #who

exec sp_who active  --看哪個引起的阻塞,blk

insert into #lock

exec sp_lock  --看鎖住了那個資源id,objid

declare @dbname nvarchar(20);

set @dbname='stmo'

select #who.* from #who where dbname=@dbname

select #lock.* from #lock

join #who

on #who.spid=#lock.spid

and dbname=@dbname

--最後傳送到sql server的語句

declare crsr cursor for

select blk from #who where dbname=@dbname and blk<>0;

declare @blk int

open crsr

fetch next from crsr into @blk

while (@@fetch_status = 0)

begin

dbcc inputbuffer(@blk)

fetch next from crsr into @blk

endclose crsr

deallocate crsr

--鎖定的資源

select #who.spid,hostname,objid,[type],mode,object_name(objid) as objname from #lock

join #who

on #who.spid=#lock.spid

and dbname=@dbname

where objid<>0

drop table #who

drop table #lock

MySQL 死鎖查詢

1 查詢是否鎖表 show open tables where in use 0 查詢到相對應的程序 然後 kill id 2 查詢程序 show processlist 補充 檢視正在鎖的事務 select from information schema.innodb locks 檢視等待鎖的事務...

MySQL 死鎖查詢

1 查詢是否鎖表 show open tables where in use 0 查詢到相對應的程序 然後 kill id 2 查詢程序 show processlist 補充 檢視正在鎖的事務 select from information schema.innodb locks 檢視等待鎖的事務...

查詢死鎖 和 解決死鎖

sql中執行 sp who lock kill 1 1 語句中查詢出來的id set ansi nulls on go set quoted identifier on go alter procedure dbo sp who lock as begin declare spid int decl...