What is a transaction in MySQL? Explain ACID

A transaction is a group of statements that are saved together (COMMIT) or cancelled together (ROLLBACK). It needs the InnoDB engine.

START TRANSACTION;
UPDATE accounts SET balance = balance - 200 WHERE id = 1;
UPDATE accounts SET balance = balance + 200 WHERE id = 2;
COMMIT;
ACIDMeaning
AtomicityAll or nothing
ConsistencyData stays valid
IsolationTransactions do not disturb each other
DurabilitySaved data survives a crash

See MySQL Transactions.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.