What is a Transaction?
A transaction is a sequence of operations performed as a single logical unit of work. It either completes fully or rolls back.
ACID Properties
- Atomicity: All operations succeed or none do.
- Consistency: Database moves from one valid state to another.
- Isolation: Concurrent transactions do not interfere with each other.
- Durability: Committed transactions survive system failures.
Concurrency Problems
- Dirty Read: Reading uncommitted data from another transaction.
- Non-repeatable Read: Same query returns different results in one transaction.
- Phantom Read: New rows appear between two reads in one transaction.
Deadlock
Two transactions wait for each other to release locks. Resolved by timeout or deadlock detection and rollback.