SQL / MySQL Advanced Database · 1 min read

Basic transaction

Start the SQL / MySQL learning path »

❮ SQL / MySQL Home All Tutorials ❯

How do I commit or roll back multiple writes?

START TRANSACTION / COMMIT.

Example

SQL / MySQL Example
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
-- ROLLBACK; if something failed

Line-by-Line Walkthrough

Use transactions for multi-step money/inventory updates.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…