Record Locking

Record locking is the technique of preventing simultaneous access to data in a database, to prevent inconsistent results.

The classic example is demonstrated by two bank clerks attempting to update the same bank account for two different transactions. Clerks 1 and 2 both retrieve (i.e., copy) the account's record. Clerk 1 applies and saves a transaction. Clerk 2 applies a different transaction to his saved copy, and saves the result, based on the original record and his changes, overwriting the transaction entered by clerk 1. The record no longer reflects the first transaction, as if it had never taken place.

A simple way to prevent this is to lock the file whenever a record is being modified by any user, so that no other user can save data. This prevents records from being overwritten incorrectly, but allows only one record to be processed at a time, locking out other users who need to edit records at the same time.

To allow several users to edit a database table at the same time and also prevent inconsistencies created by unrestricted access, a single record can be locked when retrieved for editing or updating. Anyone attempting to retrieve the same record for editing is denied write access because of the lock (although, depending on the implementation, they may be able to view the record without editing it). Once the record is saved or edits are canceled, the lock is released. Records can never be saved so as to overwrite other changes, preserving data integrity.

In database management theory, locking is used to implement isolation among multiple database users. This is the "I" in the acronym ACID.

A thorough and authoritative description of locking was written by Jim Gray.

Read more about Record LockingGranularity of Locks, Use of Locks

Other articles related to "record locking, record":

Record Locking - Use of Locks - Shared Locks
... locks allow all holders to read the contents of the record knowing that the record cannot be changed until after the lock has been released by all holders ... Exclusive locks cannot be obtained when a record is already locked (exclusively or shared) by another entity ...

Famous quotes containing the word record:

    We are at war with the most dangerous enemy that has ever faced mankind in his long climb from the swamp to the stars, and it has been said if we lose that war, and in so doing lose this way of freedom of ours, history will record with the greatest astonishment that those who had the most to lose did the least to prevent its happening.
    Ronald Reagan (b. 1911)