SQLMentor // glossary

Lock

A lock is a mechanism that restricts concurrent access to a row, page, or table so that simultaneous transactions can't corrupt each other's changes — the traditional alternative (or complement) to MVCC for enforcing isolation.

Locks range in granularity from row-level (only one row blocked) to table-level (the whole table blocked), and in strength from shared/read locks (many readers allowed, no writers) to exclusive/write locks (nobody else can read or write). Finer-grained locks allow more concurrency but cost more overhead to track; a database may automatically escalate many row locks into one table lock under heavy contention.

Two transactions each waiting on a lock the other holds is a deadlock — the database detects the cycle and forcibly rolls one transaction back.