SQL Server › Deadlocks

How would you read a deadlock graph to identify the exact queries and resources that caused a specific deadlock?

Advanced

Answer

You examine the captured XML deadlock report, looking at the process list to see each transaction's query text and the resource list to see exactly which locks each transaction was holding and waiting for, letting you trace the cycle of dependencies and pinpoint which two operations were actually conflicting with each other.
-- Deadlock graph XML includes process-list and resource-list sections
-- showing exactly which queries and locks were involved
SELECT CAST(event_data AS XML) FROM sys.fn_xe_file_target_read_file('Deadlocks*.xel', NULL, NULL, NULL);
Real-world example A developer reads through a captured deadlock graph and discovers two stored procedures were updating the same two tables in opposite order, immediately explaining why the deadlock kept occurring.

Common follow-ups: What tools provide a more visual way to interpret a deadlock graph than raw XML?;How do you correlate a deadlock graph back to the actual application code that caused it?