ROLLBACK

回滚当前会话中的未完成事务。

另请参阅:

BEGINCOMMITSHOW TRANSACTIONSDESCRIBE TRANSACTION

语法

ROLLBACK [ WORK ]
Copy

参数

WORK

可选关键字,提供与其他数据库系统的兼容性。

示例

开始一个事务,在表中插入一些值,然后通过回滚在事务中所做的更改来完成事务:

SELECT COUNT(*) FROM A1;

+----------+
| COUNT(*) |
|----------+
|        0 |
+----------+

BEGIN NAME T4;

SELECT CURRENT_TRANSACTION();

+-----------------------+
| CURRENT_TRANSACTION() |
|-----------------------+
| 1432071523422         |
+-----------------------+

INSERT INTO A1 VALUES (1), (2);

+-------------------------+
| number of rows inserted |
|-------------------------+
| 2                       |
+-------------------------+

ROLLBACK;

SELECT COUNT(*) FROM A1;

+----------+
| COUNT(*) |
|----------+
|        0 |
+----------+

SELECT CURRENT_TRANSACTION();

+-----------------------+
| CURRENT_TRANSACTION() |
|-----------------------+
| [NULL]                |
+-----------------------+

SELECT LAST_TRANSACTION();

+--------------------+
| LAST_TRANSACTION() |
|--------------------+
| 1432071523422      |
+--------------------+
Copy
语言: 中文