SQL: transactions with COMMIT and ROLLBACK
A transaction groups several statements into one all-or-nothing unit. BEGIN starts it, COMMIT makes all its changes permanent, and ROLLBACK undoes all of them. This is the atomicity of ACID: a transfer that subtracts from one account and adds to another must never be left half done, even if the system fails between the two statements.
SQL
CREATE TABLE account (id INTEGER PRIMARY KEY, owner TEXT, balance INTEGER CHECK (balance >= 0));
INSERT INTO account VALUES (1, 'Ada', 100), (2, 'Bo', 50);
BEGIN;
UPDATE account SET balance = balance - 30 WHERE id = 1;
UPDATE account SET balance = balance + 30 WHERE id = 2;
ROLLBACK;
SELECT owner, balance FROM account ORDER BY id;
BEGIN;
UPDATE account SET balance = balance - 30 WHERE id = 1;
UPDATE account SET balance = balance + 30 WHERE id = 2;
COMMIT;
SELECT owner, balance FROM account ORDER BY id;