0
0
MySQLquery~10 mins

ACID properties in MySQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - ACID properties
Start Transaction
Perform Operations
Check Atomicity
Check Consistency
Check Isolation
Check Durability
Commit or Rollback
End
This flow shows how a database transaction follows ACID properties step-by-step to ensure reliable data handling.
Execution Sample
MySQL
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
This transaction transfers 100 units from account 1 to account 2, ensuring ACID properties.
Execution Table
StepActionAtomicityConsistencyIsolationDurabilityResult
1START TRANSACTIONTransaction started as a single unitDatabase state unchanged yetTransaction isolated from othersChanges not yet durableTransaction open
2UPDATE accounts SET balance = balance - 100 WHERE id = 1Partial update done, still part of transactionBalance remains consistent (no negative if checked)Other transactions cannot see this change yetChange not durable until commitBalance of account 1 decreased by 100 in transaction
3UPDATE accounts SET balance = balance + 100 WHERE id = 2Still atomic, both updates part of one transactionBalances consistent after updateIsolation maintainedNot durable yetBalance of account 2 increased by 100 in transaction
4COMMITAll changes applied together or noneDatabase state consistent after commitChanges visible to other transactions nowChanges saved permanentlyTransaction committed successfully
5ENDTransaction finishedDatabase consistentIsolation no longer appliesDurability ensuredTransaction complete
💡 Transaction ends after COMMIT, ensuring all ACID properties are met.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4 (Commit)
balance_account_11000900900900
balance_account_2500500600600
transaction_statenoneopenopencommitted
Key Moments - 3 Insights
Why does the balance of account 1 not permanently change after step 2?
Because the transaction is still open (see execution_table step 2), changes are not durable or visible outside until COMMIT.
How does isolation protect the transaction during updates?
Isolation ensures other transactions cannot see partial changes (execution_table steps 2 and 3), preventing inconsistent reads.
What happens if the transaction is rolled back instead of committed?
All changes are undone together, maintaining atomicity and consistency by not applying partial updates.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of 'transaction_state' after step 3?
Acommitted
Bnone
Copen
Drolled back
💡 Hint
Check variable_tracker column 'After Step 3' for 'transaction_state'
At which step do changes become permanent and visible to other transactions?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Look at execution_table step 4 under Durability and Isolation columns
If the transaction was rolled back after step 3, what would happen to the balances?
ABalances revert to start values
BOnly account 1 balance reverts
CBalances remain changed as in step 3
DOnly account 2 balance reverts
💡 Hint
Atomicity means all or nothing; see key_moments explanation about rollback
Concept Snapshot
ACID properties ensure reliable transactions:
Atomicity: all or nothing changes
Consistency: valid data state
Isolation: transactions don't interfere
Durability: changes saved permanently
Use START TRANSACTION, COMMIT, ROLLBACK in SQL
Full Transcript
This visual execution traces a simple money transfer transaction in MySQL demonstrating ACID properties. The transaction starts, performs two updates, then commits. Atomicity ensures both updates succeed or fail together. Consistency keeps balances valid. Isolation hides partial changes from others. Durability saves changes permanently after commit. Variable tracking shows balances and transaction state at each step. Key moments clarify why changes are not permanent before commit and how rollback would undo all changes. The quiz tests understanding of transaction states and ACID effects.