SQL Flow Field Guide

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

  1. 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.
  2. 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.
  3. Open the xml_deadlock_report captured by the default system_health Extended Events session. Identify the victim list, process list, and resource list.
  4. 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.
  5. 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.
  6. Read Microsoft's deadlock guide and system_health event 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