Preparing your workspace
Transactions group multiple database operations into a unit that can be committed together or rolled back when something fails.
Transactions are important when several changes must remain consistent. MySQL transactions commonly use START TRANSACTION, COMMIT, and ROLLBACK. ACID describes important transaction properties: Atomicity means the operation behaves as one unit, Consistency preserves valid rules, Isolation controls interaction between concurrent transactions, and Durability means committed changes are preserved according to the database system. Transactions are especially important for financial, enrollment, inventory, and other multi-step operations.
An enrollment workflow may create an enrollment record and reduce available course capacity as part of one transaction.
START TRANSACTION; INSERT INTO enrollments (student_id, course_id) VALUES (1, 5); UPDATE courses SET enrolled_count = enrolled_count + 1 WHERE id = 5; COMMIT;
The enrollment insert and course count update are committed together.