Transaction is a logical unit of work carried out by a single execution (of a program or an application) that reads or writes (updates/changes) the contents’ (one or more data items) values of the database.
The main operations of a transaction are:
Read(A): Read operations Read(A) or R(A) reads the value of A from the database.
Write (A): Write operation Write(A) or W(A) writes the value back to the database.
Example Transaction: Transfers Rs 500 from A’s account to B’s account.
Two main issues to deal with:
- Failures of various kinds, such as hardware failures and system crashes
- Concurrent execution of multiple transactions
Database has two important operations to avoid these issues:
Commit: After all instructions of a transaction are successfully executed, the changes made by transaction are made permanent in the database.
Rollback: If a transaction is not able to execute all operations successfully, all the changes made by transaction are undone.