SQLite Forum

Recover Database
Login
Exactly.  

A `SAVEPOINT` is exactly what its name implies -- it is a named place in the progress of a transaction which you can ROLLBACK TO (ie, undo everything done after that named location) so you can try again (or do a different path).  The RELEASE command searches for the given savepoint name marker and removes all savepoint names back to and including the one specified.

There is no requirement for the SAVEPOINT names to be unique within a transaction.  The search for a SAVEPOINT name to ROLLBACK TO or RELEASE starts from the current position and works backwards in time.

If you try to `ROLLBACK TO` or `RELEASE` a savepoint that does not exist, you get an error message and nothing is done.

```
sqlite> create table x(x);
sqlite> begin;
sqlite> savepoint a;
sqlite> insert into x values (1);
sqlite> savepoint a;
sqlite> insert into x values (2);
sqlite> savepoint a;
sqlite> insert into x values (3);
sqlite> select * from x;
┌───┐
│ x │
├───┤
│ 1 │
│ 2 │
│ 3 │
└───┘
sqlite> release a;
sqlite> select * from x;
┌───┐
│ x │
├───┤
│ 1 │
│ 2 │
│ 3 │
└───┘
sqlite> rollback to a;
sqlite> select * from x;
┌───┐
│ x │
├───┤
│ 1 │
└───┘
sqlite> rollback to x;
Error: no such savepoint: x
sqlite> select * from x;
┌───┐
│ x │
├───┤
│ 1 │
└───┘
sqlite> end;
```