1.

What is a lock. Explain the major difference between a shared lock and an exclusive lock during a transaction in a database.

Answer»

A database lock is a mechanism to protect a shared PIECE of data from getting updated by two or more database users at the same time. When a single database user or SESSION has acquired a lock then no other database user or session can modify that data until the lock is released.

  • Shared Lock: A shared lock is required for reading a data item and many transactions may hold a lock on the same data item in a shared lock. Multiple transactions are allowed to read the data items in a shared lock.
  • Exclusive lock: An exclusive lock is a lock on any transaction that is about to perform a write operation. This type of lock doesn’t allow more than ONE transaction and hence PREVENTS any INCONSISTENCY in the database. 


Discussion

No Comment Found