SQL DDL and DML/Use savepoints

Create partial rollback points inside a transaction.

Section: Transactions

Use savepoints

sql
sql
BEGIN;
SAVEPOINT before_optional_step;
UPDATE orders SET status = "archived" WHERE order_id = 10;
ROLLBACK TO SAVEPOINT before_optional_step;
COMMIT;
Explanation

Savepoints let you recover from part of a transaction without aborting the whole unit of work.

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
Begin, commit, and rollback
Wrap multiple changes in one 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.