A transaction is a unit of program execution that accesses and possibly updates one or more data items in the database.
Money transfer from an account to another account.
Transaction to transfer Rs 1000 from account A to account B:
- A := A – 500
- B := B + 500
Two main issues to deal in transaction:
- Failures of various kinds, such as hardware failures and system crashes
- Concurrent execution of multiple transactions
A transction must follow ACID properties.
Either all operations of the transaction are properly reflected in the database or none are.
Execution of a transaction in isolation preserves the consistency of the database.
Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions.
After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.
Active, the initial state; the transaction stays in this state while it is executing
2. Partially commited
Partially committed, after the final statement has been executed.
Failed, after the discovery that normal execution can no longer proceed.
Aborted, after the transaction has been rolled back and the database restored to its state prior to the start of the transaction. Two options after it has been aborted:
- restart the transaction – only if no internal logical error
- kill the transaction
Committed, after successful completion.