H2 Database 简明教程

H2 Database - Rollback

回滚是 SQL 语法的命令,用于将事务回滚到保存点或前一个事务。通过使用此命令,我们可以回滚到特定保存点,也可以回滚到之前执行的事务。

ROLLBACK is a command from the SQL grammar used to roll back the transaction to a Savepoint or to the previous transaction. By using this command, we can either roll back to the specific Savepoint or we can roll back to the previous executed transaction.

Syntax

ROLLABCK 命令有两种不同的语法。

There are two different syntaxes for ROLLABCK command.

以下是对回滚命令的通用语法。

Following is the generic syntax for the rollback command.

ROLLBACK [ TO SAVEPOINT savepointName ]

以下是回滚命令的通用语法,适用于特定事务。

Following is the generic syntax of the Rollback command to the specific transaction.

ROLLBACK TRANSACTION transactionName

Example 1

在此示例中,我们将使用以下命令将当前事务回滚到名为 sp1_test 的保存点。

In this example, we will roll back 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

在以下示例中,我们将使用给定的命令回滚名为 tx_test 的完整事务。

In the following example, we will roll back the complete transaction named tx_test using the given command.

ROLLBACK TRANSACTION tx_test;

以上命令会产生以下输出。

The above command produces the following output.

Rollback successfully