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
但我不知道如何结合两个查询,以便我可以获得锁定事务查询。任何帮助表示感谢。
答案 0 :(得分: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'