1

Sqlserver 2005-2008 查询找出死锁并识别查询文本

我有以下可以给我锁定状态的查询也告诉我导致锁定的命令

SELECT
    object_name(sl.resource_associated_entity_id) as 'TableName' ,
    dr.command,
    sl.*
FROM
    sys.dm_tran_locks as sl
        LEFT JOIN
        sys.dm_exec_requests dr
        ON
        sl.request_session_id=dr.session_id
WHERE
    sl.resource_type = 'OBJECT'

我有另一个查询,它给了我查询文本,如下所示

SELECT top 5 deqs.last_execution_time AS [Time], dest.text AS [Query],
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC

但我不知道如何结合这两个查询,以便获得锁定事务查询。任何帮助表示赞赏。

4

1 回答 1

2

我创建了这个查询应该可以工作。

 SELECT
        object_name(sl.resource_associated_entity_id) as 'TableName' ,
        dr.command, dest.text ,
        sl.*
    FROM
        sys.dm_tran_locks as sl
            LEFT JOIN
            sys.dm_exec_requests dr
            ON
            sl.request_session_id=dr.session_id

            CROSS APPLY sys.dm_exec_sql_text(dr.sql_handle) AS dest

    WHERE
        sl.resource_type = 'OBJECT'
于 2013-04-03T19:21:41.250 回答