In: Computer Science
Discuss why the COMMIT and ROLLBACK statements are necessary, and explain their relationship to one of the transaction properties. Discuss all four possible concurrency problems and provide examples of each.
Why commit is necessary
COMMIT is necessary to permantly store the changes done after the transaction done and to end the transaction that it is completed
Why rollback is necessary
ROLLBACk is necessary in transaction suppose some error occured during transaction by human errror or machine error then ROLLBACK command is executed to restore all the data to previos condition, without it there may many exception will occur.
Their relationship to Atomicity (transaction property)
In atomicity data is operated as a single operation that is all changes are mode or none of them are made.
so commit and rollback ensure that Atomicity of the transaction remain maintain during any transaction.
PROBLEMS in concurrency
Multi-User
Example: In this problem suppose two person requested same data but one is for readin and other one is for writing then the data is reflected to first one and he/she read the outdated data.
Uncommited data
Example: This occur whe two transaction T1 and T2 executed at same time and T1 is rolled back after T2 already reads the uncommited data.
Inconsistent Data
Example: This happen when T1 is calculating over some data meanwhile T2 is updating the same data, this result to the inconsistent data to T1
Lost Data Updates
Example: This happen when T1 and T2 updating the same data at same time and update from one transaction is overwritten by other.