我在博客上找到了以下查询,但它仅获取受害者信息:
select top (1) with ties t1.*
from table1 t1 inner join
table2 t2
on t2.pid = t1.pid
order by row_number() over (partition by t2.pid order by t2.id desc);
现在,我想从资源列表中获取对象名称。我无法理解SELECT
DATEADD(mi, DATEDIFF(mi, GETUTCDATE(), CURRENT_TIMESTAMP), DeadlockEventXML.value('(event/@timestamp)[1]', 'datetime2')) AS [EventTime],
DeadlockEventXML.value('(//process[@id[//victim-list/victimProcess[1]/@id]]/@hostname)[1]', 'nvarchar(max)') AS HostName,
DeadlockEventXML.value('(//process[@id[//victim-list/victimProcess[1]/@id]]/@clientapp)[1]', 'nvarchar(max)') AS ClientApp,
DB_NAME(DeadlockEventXML.value('(//process[@id[//victim-list/victimProcess[1]/@id]]/@currentdb)[1]', 'nvarchar(max)')) AS [DatabaseName],
DeadlockEventXML.value('(//process[@id[//victim-list/victimProcess[1]/@id]]/@transactionname)[1]', 'nvarchar(max)') AS VictimTransactionName,
DeadlockEventXML.value('(//process[@id[//victim-list/victimProcess[1]/@id]]/@isolationlevel)[1]', 'nvarchar(max)') AS IsolationLevel,
DeadlockEventXML.query('(event/data[@name="xml_report"]/value/deadlock)[1]') AS DeadLockGraph,
DeadlockEventXML,
CONVERT(DATE, GETDATE())
FROM
(SELECT
XEvent.query('.') AS DeadlockEventXML,
Data.TargetData
FROM
(SELECT
CAST(target_data AS XML) AS TargetData,
CONVERT(DATE, GETDATE()) as InsertedDate
FROM
sys.dm_xe_session_targets st
JOIN
sys.dm_xe_sessions s ON s.address = st.event_session_address
WHERE
s.name = 'DeadLock'
AND st.target_name = 'ring_buffer') AS Data
CROSS APPLY
TargetData.nodes('RingBufferTarget/event[@name="xml_deadlock_report"]') AS XEventData(XEvent)) AS DeadlockInfo
声明。
我想获取死锁过程中包含的两个对象名。使用这种方法,我该如何获取它?