码迷,mamicode.com
首页 > 数据库 > 详细

查询SQL阻塞语句

时间:2014-11-19 18:00:46      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   os   sp   数据   on   div   

SELECT SPID=p.spid,
       DBName = convert(CHAR(20),d.name),
       ProgramName = program_name,
       LoginName = convert(CHAR(20),l.name),
       HostName = convert(CHAR(20),hostname),
       Status = p.status,
       BlockedBy = p.blocked,
       LoginTime = login_time,
       QUERY = CAST(TEXT AS VARCHAR(MAX))
FROM   MASTER.dbo.sysprocesses p
       INNER JOIN MASTER.dbo.sysdatabases d
         ON p.dbid = d.dbid
       INNER JOIN MASTER.dbo.syslogins l
         ON p.sid = l.sid
       CROSS APPLY sys.dm_exec_sql_text(sql_handle)
WHERE  p.blocked = 0
       AND EXISTS (SELECT 1
                   FROM   MASTER..sysprocesses p1
                   WHERE  p1.blocked = p.spid)
                   
                   
exec sp_who_lock

上面一个是SQL语句,一个是存储过程,可以查询当前数据库阻塞的存储过程和SQL语句

查询SQL阻塞语句

标签:style   blog   ar   color   os   sp   数据   on   div   

原文地址:http://www.cnblogs.com/flyfish2012/p/4108412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!