SyntaxStudy
Sign Up
MySQL Beginner 3 min read

MySQL Transactions

Transactions

A transaction is a unit of work that either completes fully (COMMIT) or is rolled back entirely (ROLLBACK). Transactions ensure ACID guarantees.

Example
START TRANSACTION;
UPDATE accounts SET balance = balance - 500 WHERE id = 1;
UPDATE accounts SET balance = balance + 500 WHERE id = 2;
-- If both updates succeed:
COMMIT;
-- If anything goes wrong:
-- ROLLBACK;
Pro Tip

All statements between START TRANSACTION and COMMIT behave as a single atomic operation.