← CodePrimer
SQL Advanced Database

Basic transaction

How do I commit or roll back multiple writes?

START TRANSACTION / COMMIT.

Sample
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

Notes

Use transactions for multi-step money/inventory updates.

Keywords: transaction · commit · rollback

Related

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share