SQL SERVER查询锁

阅读更多
with Lock(level, dbName,spid,blocked,sql_handle)  
as 
(select 0 as level, db_name(dbid),spid,blocked,sql_handle from master..sysprocesses a where blocked > 0
union all
select level + 1 as Level, db_name(a.dbid),a.spid,a.blocked,a.sql_handle from master..sysprocesses a join lock b on a.spid = b.blocked and a.spid <> a.blocked
where level < 5)  
select distinct a.level, a.dbName, a.spid, a.blocked,
case when (a.blocked <> 0) then 'blocked' else 'blocker' end as actor, b.*
from Lock a cross apply sys.dm_exec_sql_text(a.sql_handle)b
order by actor desc

你可能感兴趣的:(SQL SERVER查询锁)