sql / beginner
Snippet
Discarding Uncommitted Changes with ROLLBACK
The ROLLBACK command undoes all modifications performed within the current transaction, returning the database to its state before the transaction began.
snippet.sql
sql
1
2
3
START TRANSACTION;UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;ROLLBACK;
Breakdown
1
START TRANSACTION;
Initiates a explicit multi-statement transaction scope.
2
UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;
Applies a temporary deduction to account_id 1.
3
ROLLBACK;
Aborts the transaction and discards the balance update.