Several writers at once.
WHAT A LOCK DOES
Prevents conflicting access while a change is in progress.
WHAT LEVELS EXIST
Row level Table level
WHY ROW LEVEL IS PREFERRED
It permits far more concurrency.
WHAT SHARED AND EXCLUSIVE MEAN
Shared permits other readers; exclusive permits nobody.
WHAT A DEADLOCK IS
Two transactions each holding what the other needs.
WHAT THE DATABASE DOES
Detects it and aborts one.
WHAT THE APPLICATION MUST DO
Catch the error and retry.
WHY RETRY IS THE CORRECT RESPONSE
Deadlocks are normal under concurrency, not a fault.
WHAT REDUCES THEM
Accessing tables in a consistent order Keeping transactions short Indexing, so fewer rows are locked
WHY INDEXING AFFECTS LOCKING
Without an index, a condition locks far more rows than it matches.
WHAT LOCK WAIT TIMEOUTS INDICATE
A transaction holding locks too long.
HOW TO FIND IT
The list of running transactions and what they wait on.
WHAT TO LOOK FOR
A transaction open for a long time doing nothing.
WHAT CAUSES THAT
An application that began a transaction and did not commit.
WHAT TO CHECK IN CODE
That every path commits or rolls back.
WHAT OPTIMISTIC LOCKING IS
Checking a version column on update rather than holding a lock.