Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
In relational database management systems, a Transaction is a logical unit of work that contains one or more SQL statements executed as a single, indivisible operation. The cornerstone of transactional reliability is the acronym ACID: Atomicity, Consistency, Isolation, and Durability.
Understanding ACID properties is vital for building resilient backend applications, preventing financial inaccuracies, and avoiding race conditions in concurrent multi-user environments.
Every statement in a transaction must execute successfully to be saved. If any single statement fails or errors out mid-way, the entire transaction is rolled back, leaving the database in its original state as if nothing ever happened.
Example: In a bank transfer of $500 from Account A to Account B:
If step 2 crashes the server, step 1 is rolled back so money does not simply vanish into thin air.
A transaction can only transition the database from one valid state to another valid state. All schema constraints, primary keys, foreign keys, unique rules, check constraints, and cascade triggers must be satisfied at commit time.
Concurrent transactions executed simultaneously by thousands of users must not interfere with or corrupt each other. The intermediate state of an in-progress transaction is hidden from other concurrent transactions until committed.
Once a transaction is successfully committed, its changes are guaranteed to persist permanently—even if an immediate power outage, OS crash, or hardware failure occurs seconds later. In MySQL InnoDB, this is achieved through the Write-Ahead Logging (WAL) mechanism known as the Redo Log (ib_logfile).
| ACID Property | InnoDB Mechanism |
|---|---|
| Atomicity | Undo Logs (Rollback segments track inverse operations) |
| Consistency | Doublewrite Buffer, constraints enforcement, crash recovery |
| Isolation | Row-level locking and MVCC (Multi-Version Concurrency Control) |
| Durability | Redo Log (WAL - flushed to disk on commit via innodb_flush_log_at_trx_commit) |
A crucial reason MySQL adopted InnoDB as its default storage engine (replacing MyISAM in MySQL 5.5) is ACID compliance:
UPDATE of 1000 rows, 500 rows remain updated and 500 un-updated with zero rollback capability.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Positional Value Functions: LEAD and LAG | Transaction Control: START TRANSACTION, COMMIT, ROLLBACK |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.