SQLMentor // glossary

Deadlock

A deadlock occurs when two transactions each hold a lock the other needs, so neither can proceed. The database detects the cycle and aborts one transaction (the victim) to break it.

Classic case: transaction A locks row 1 then waits for row 2, while transaction B locks row 2 then waits for row 1. Neither can finish. The database's deadlock detector rolls back one of them, which should be retried by the application.

You reduce deadlocks by accessing tables and rows in a consistent order, keeping transactions short, and using the lowest isolation level that is still correct.