SQL DDL and DML/Begin, commit, and rollback

Wrap multiple changes in one transaction.

Section: Transactions

Begin, commit, and rollback

sql
sql
BEGIN;

UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;
UPDATE accounts SET balance = balance + 100 WHERE account_id = 2;

COMMIT;
Explanation

If something fails, use ROLLBACK instead of COMMIT.

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
Use savepoints
Create partial rollback points inside a transaction.
OpenIn sheetsqlsame section
Set transaction isolation level
Control how concurrent transactions interact.
OpenIn sheetsqlsame section
Create table
Define a new table with columns and constraints.
Define primary key
Mark a column as the main row identifier.
Insert one row
Add a single row to a table.
Add a column
Modify an existing table by adding a new column.