SQL Server Interview Question #149

What is a lock in SQL Server?

Transactions, Locking, Blocking & Deadlocks Senior Advanced

Detailed Explanation

A lock is a concurrency-control mechanism used by SQL Server to protect data and coordinate simultaneous access by multiple transactions.

Depending on the operation and isolation level, SQL Server can acquire locks at different resources such as keys, pages, tables, metadata, and other internal structures. Common lock modes include Shared (S), Exclusive (X), Update (U), Intent locks, and schema locks.

Locks are normal and necessary; the performance problem is usually excessive contention or locks being held longer than necessary.