H2 Database - Rollback

H2 Database - Rollback

ROLLBACK is an SQL grammar command used to roll back a transaction to a savepoint or previous transaction. Using this command, we can either rollback to a specific savepoint or rollback to a previous completed transaction.

Syntax

There are two different syntaxes for the ROLLABCK command.

Following is the general syntax of the rollback command.

Rollback [To Savepoint SavePointName] 

The following is the general syntax for the Rollback to a specific transaction command.

ROLLBACK TRANSACTION transactionName 

Example 1

In this example, we will rollback the current transaction to a savepoint named sp1_test using the following command.

ROLLBACK sp1_test; 

The above command produces the following output.

Rollback successfully 

Example 2

In the following example, we will rollback the entire transaction named tx_test using the given command.

ROLLBACK TRANSACTION tx_test;

The above command produces the following output.