Sobes.tech
Junior — Middle

What types of locks are used in database management systems to ensure data integrity?

sobes.tech AI

Answer from AI

In a DBMS, various types of locks are used to ensure data integrity:

  • Row-level locks — lock individual records, allowing other transactions to work with the remaining data.
  • Table-level locks — lock the entire table, preventing access by other transactions.
  • Page-level locks — lock specific data pages within a table.
  • Shared locks — allow multiple transactions to read data but prevent writing.
  • Exclusive locks — prevent other transactions from reading or writing.

For example, when performing a record update, the DBMS may set an exclusive lock on that row to prevent other transactions from modifying it simultaneously, which prevents data loss and ensures consistency.