MySQL Transactions and Locking Cheatsheet/Set and rollback to a savepoint

Undo only part of a transaction.

Section: transactions

Set and rollback to a savepoint

sql
sql
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
SAVEPOINT after_debit;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
ROLLBACK TO SAVEPOINT after_debit;
COMMIT;
Explanation

Savepoints are useful when a larger transaction contains optional or retryable steps.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing transactions
Rollback a transaction
Undo all uncommitted changes.
OpenIn sheetsqlsame section
Start a transaction
Begin a transaction explicitly.
OpenIn sheetsqlsame section
Commit a transaction
Persist all changes made in the current transaction.
OpenIn sheetsqlsame section
Disable autocommit for the session
Keep statements in a transaction until you commit or rollback.
OpenIn sheetsqlsame section
Lock selected rows for update
Prevent concurrent modifications to matched rows inside a transaction.
Lock rows for shared reads
Read rows while protecting against conflicting writes.