What is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed

concurrencydatabase

what is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed?

I'm having trouble with this. and what are some informal examples for concurrency control.
any help would be greatly appreciated.

Best Answer

Concurrent execution of database transactions in a multi-user system means that any number of users can use the same database at the same time. Concurrency control is needed in order to avoid inconsistencies in the database.

Here is an example of how this scenario can lead to an inconsistency:

Assume we have two users, Alice and Bob, who both have access to the same bank account. Alice wants to deposit $100 and Bob wants to withdraw $200. Assuming there is $500 in the account, here is how the execution might take place if they perform their actions at the same time:

  1. Alice gets initial amount (x = $500)
  2. Bob gets initial amount (x = $500)
  3. Alice deposits $100 (x + 100) = $600
  4. Bob withdraws $200 (x - 200) = $300
  5. Alice saves the new balance ($600)
  6. Bob saves the new balance ($300)

New balance after both actions should be $400. Now the database is in an inconsistent state.

Concurrency control can prevent inconsistencies by providing Alice with a temporary "lock" on the database until she is done with her action.