Read a deadlock graph and explain the victim
Reproduce a controlled two-session deadlock in a disposable database and use its graph to identify the cycle and victim.
What you are trying to do
This is a guided SQL Server sandbox drill. It requires two sessions and an instructor-seeded table with two disposable rows. The sql field is empty because timing, shared state, and the rollback outcome depend on both sessions.
Work through it
- In Session A, begin a transaction, update row 1, wait five seconds, then update row 2 and commit. In Session B, start within that delay, begin a transaction, update row 2, wait five seconds, then update row 1 and commit.
- Use only the dedicated lab table. The reversed lock order creates a cycle. One statement should receive error 1205 and its transaction is selected as the deadlock victim.
- Open the
xml_deadlock_reportcaptured by the defaultsystem_healthExtended Events session. Identify the victim list, process list, and resource list. - Trace each process's held resource and requested resource to draw the wait-for cycle. Compare the deadlock priority and transaction cost evidence when explaining why SQL Server selected a victim.
- Repeat after changing both workflows to acquire resources in the same order. Compare the captured graph. Do not disable deadlock detection or clear the server event session.
- Read Microsoft's deadlock guide and
system_healthevent details. Deadlocks guide · system_health session
Check your work
The graph shows two processes, two resources, and a circular wait. One process is the victim. Consistent resource ordering removes the cycle in the repeated drill.
Knowledge check
Commands in this lesson
Next lesson Reproduce a lost update and protect the write