Databases & Data Storage

Database Locking

Definition

Locking is a mechanism used by database management systems to protect a piece of data (like a row or a table) from being accessed by more than one transaction at the same time. This is essential for preventing data corruption in a multi-user environment.

Why It Matters

Locking is the primary mechanism for ensuring "Isolation," the "I" in ACID. It prevents concurrent transactions from interfering with each other and causing data inconsistencies.

Contextual Example

When a transaction begins to update a row, it places an "exclusive lock" on that row. This prevents any other transaction from reading or writing to that row until the first transaction is committed or rolled back.

Common Misunderstandings

  • There are different types of locks (e.g., shared locks for reading, exclusive locks for writing) and different levels of locking (row-level, page-level, table-level).
  • Locking is a trade-off. While it ensures consistency, it can also reduce concurrency and lead to performance bottlenecks or deadlocks if not managed properly.

Related Terms

Last Updated: December 17, 2025