Transactions
DraftA transaction groups statements into one unit of work. You either commit the whole change or roll it back.
Commit a transfer
COMMIT makes every statement in the transaction durable together.
Loaded Database:transactions.database-init
BEGIN;
UPDATE accounts SET balance_cents = balance_cents - 1000 WHERE name = 'Ada';
UPDATE accounts SET balance_cents = balance_cents + 1000 WHERE name = 'Grace';
COMMIT;
SELECT name, balance_cents FROM accounts ORDER BY name;Loading plan...Rollback a transfer
ROLLBACK throws away the changes made inside the transaction.
Loaded Database:transactions.database-init
BEGIN;
UPDATE accounts SET balance_cents = balance_cents - 1000 WHERE name = 'Ada';
UPDATE accounts SET balance_cents = balance_cents + 1000 WHERE name = 'Grace';
ROLLBACK;
SELECT name, balance_cents FROM accounts ORDER BY name;Loading plan...