A database lock is a concurrency control mechanism that restricts access to database resources such as rows, pages, or tables when multiple transactions run at the same time.
Common types:
Shared Lock (S-Lock). Used for read operations (
SELECT). Multiple transactions can hold a shared lock on the same data simultaneously, but no transaction can modify the data until all shared locks are released.Exclusive Lock (X-Lock). Used for write operations (
INSERT,UPDATE,DELETE). Only one transaction can hold an exclusive lock on a resource at a time, blocking all other reads and writes until the transaction finishes.Update Lock (U-Lock). Used when a transaction reads a record with the intent to update it later. It prevents deadlocks caused when two transactions hold shared locks and both try to upgrade to exclusive locks at once.
Loading…