Guided Notes

Transactions, Procedures & Users

All-or-nothing changes with START TRANSACTION, COMMIT, and ROLLBACK, ACID, stored procedures, and managing users and privileges.

Transactions

Slide 1 / 5

A transaction groups statements so they succeed or fail together:

START TRANSACTION; UPDATE products SET stock = stock - 2 WHERE product_id = 14; INSERT INTO orders VALUES (108, 3, '2025-04-10', 'pending'); INSERT INTO order_items VALUES (108, 14, 2); COMMIT; -- make the changes permanent

If anything goes wrong, ROLLBACK; undoes every change since START TRANSACTION. Transactions need the InnoDB engine (the default).

← Dates & Built-in Functions