查阻塞

 

DECLARE @who TABLE
    (
      spid INT ,
      [status] VARCHAR(30) ,
      login VARCHAR(60) ,
      HostName VARCHAR(80) ,
      Blkby VARCHAR(60) ,
      DBName VARCHAR(80) ,
      Command VARCHAR(MAX) ,
      CPUTime BIGINT ,
      DiskIO BIGINT ,
      LastBatch VARCHAR(200) ,
      Progname VARCHAR(200) ,
      spid_ BIGINT ,
      RequestId INT
    )
INSERT  INTO @who
EXEC ('sp_who2') 
--select * from @who

SELECT  E.text,C.text,A.* FROM    @who A
LEFT JOIN master.dbo.sysprocesses B ON A.SPID=B.SPID
CROSS APPLY ::fn_get_sql(B.sql_handle) C
--LEFT JOIN master.dbo.sysprocesses D ON A.blkby=cast(D.SPID as varchar(30))
CROSS APPLY ::fn_get_sql(B.sql_handle) E
where DBName='数据库名'
     and 
     blkby != '  .'

 

posted @ 2016-05-27 16:07  davidhou  阅读(184)  评论(0编辑  收藏  举报