The SAVEPOINT statement marks a savepoint during a transaction, allowing you to roll back the transaction to that savepoint. Savepoints are optional and you can mark multiple savepoints within a transaction.
Mark a savepoint
After a transaction is started, you can use the following statement to mark a savepoint:
SAVEPOINT pointname;
Here, pointname specifies the name of the transaction savepoint.
The following example shows how to start a transaction and mark multiple savepoints.
obclient [test]> SET SESSION autocommit=0;
Query OK, 0 rows affected
obclient [test]> BEGIN;
Query OK, 0 rows affected
obclient [test]> INSERT INTO ordr(id, name) VALUES(6,'FR');
Query OK, 1 row affected
obclient [test]> SAVEPOINT fr;
Query OK, 0 rows affected
obclient [test]> INSERT INTO ordr(id, name) VALUES(7,'RU');
Query OK, 1 row affected
obclient [test]> SAVEPOINT ru;
Query OK, 0 rows affected
obclient [test]> INSERT INTO ordr(id, name) VALUES(8,'CA');
Query OK, 1 row affected
obclient [test]> SAVEPOINT ca;
Query OK, 0 rows affected