Database: Transaction?
I love learning about technology and sharing that with others
Motivation
learning what is transaction
Transaction is a unit of work, that we want to be treated as a whole. We want either it completes or it should fail.
Lets say we have bought some momo's from a shop and we are now paying it with the upi. So this transfer of money should either happen or it should fail, it should not go in a waiting state.
Example
accountA -= 100; accountB += 100; or
accountB += 100; accountA -= 100;
If something goes wrong between the first and the second operation in the pair you have a problem - either 100 bucks have disappeared, or they have appeared out of nowhere.
Solution
beginTransaction;
accountB += 100;
accountA -= 100;
commitTransaction;
A transaction is mechanism which will make sure either all the operation is completed or it should go back to original state.
Simple Transaction Example in Database
- Commit
- Rollback
: Commit --> to make the operation permanent : Rollback --> to rollback the system to the previous state.
What are ACID Properties?
- Atomicity : single operations , it should occur completely or should not occur
- Consistency : System should be consistent before and after transaction
- Isolation : Transaction should occur in isolation and should be isolated
- Durability : Changes should persist after the transaction.
Types of Transactions
Based on Application areas
- Non-distributed vs. distributed
- Compensating transactions
- Transactions Timing
- On-line vs. batch
Based on Actions
- Two-step
- Restricted
- Action model
Based on Structure
- Flat or simple transactions: It consists of a sequence of primitive operations executed between a begin and end operations.
- Nested transactions: A transaction that contains other transactions. Workflow

