阻塞者及阻塞数量

发布时间:2020-07-21 13:49:10 作者:Kassadar
来源:网络 阅读:189
With T
As
(
Select ROW_NUMBER() over (order by spid) as id, spid,blocked From (select distinct spid,blocked from sys.sysprocesses where spid in
    (Select blocked from sys.sysprocesses where blocked <>0) and blocked=0) S
Union All
Select  id,TB.spid,TB.blocked  From sys.sysprocesses TB Inner Join T on TB.blocked=T.SPID  AND TB.blocked<>TB.spid
),
U
AS
(select distinct a.spid,last_batch,program_name,nt_username,loginame,db_name(a.dbid) as 'dbname',OBJECT_NAME(resource_associated_entity_id,a.dbid) as 'tablename',request_mode,request_type,open_tran,waittype,status,hostname,cmd,b.text as TSQL
from sys.sysprocesses a 
cross apply sys.dm_exec_sql_text(a.sql_handle) b 
inner join sys.dm_tran_locks c on a.spid=c.request_session_id and resource_type='OBJECT' and request_mode not like 'Sch%'
where spid in
    (Select blocked from sys.sysprocesses where blocked <>0) 
    and a.blocked=0
)
select U.spid,blockeds,last_batch,program_name,nt_username,loginame,dbname,tablename,request_mode,request_type,open_tran,waittype,status,hostname,cmd,tsql from U inner join (Select distinct COUNT(id) over (partition by id)-1 as blockeds,C.spid From T A cross apply (select TOP 1 SPID from T B WHERE A.id=B.id AND B.blocked=0)C) BlKS ON U.spid=BLKS.spid;
![](https://cache.yisu.com/upload/information/20200311/41/171157.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
推荐阅读:
  1. redis阻塞分析
  2. 队头阻塞

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

阻塞 数量

上一篇:详解如何安装和使用Vue-resource

下一篇:在HTML中如何使用JavaScript

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》