What if your bank account balance got messed up because two people changed it at once?
Why Two-phase locking (2PL) in DBMS Theory? - Purpose & Use Cases
Imagine multiple people trying to edit the same document at the same time without any rules. They overwrite each other's changes, causing confusion and mistakes.
Without a system to control access, changes can clash, data can become inconsistent, and it's hard to know which version is correct. This leads to errors and lost work.
Two-phase locking (2PL) sets clear rules for when to lock and unlock data during transactions. It ensures that no two people change the same data at once, keeping everything safe and consistent.
start transaction update data commit // no locks, possible conflicts
start transaction
acquire locks
update data
commit
release locks
// safe and consistentIt enables multiple users to work on the database simultaneously without causing errors or losing data.
In a bank, two tellers updating the same account balance at the same time use 2PL to avoid mistakes like withdrawing more money than available.
2PL controls when data is locked and unlocked during transactions.
This prevents conflicts and keeps data consistent.
It allows safe multi-user access to databases.