// 开始查询空表
mysql> select * from t_x;
Empty set
// 开启事务
mysql> begin;
Query OK, 0 rows affected (0.01 sec)
// 插入第一条数据
mysql> insert into t_x value(1, '1');
Query OK, 1 row affected (0.01 sec)
// 设置保存点
mysql> savepoint a1;
Query OK, 0 rows affected (0.01 sec)
// 此时查询一条数据
mysql> select * from t_x;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
+----+------+
1 row in set (0.01 sec)
// 插入第二条数据
mysql> insert into t_x value(2, '2');
Query OK, 1 row affected (0.01 sec)
// 设置保存点2
mysql> savepoint a2;
Query OK, 0 rows affected (0.01 sec)
// 查询两条数据
mysql> select * from t_x;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 2 | 2 |
+----+------+
2 rows in set (0.01 sec)
// 插入第三条数据
mysql> insert into t_x value(3, '3');
Query OK, 1 row affected (0.01 sec)
// 共三条
mysql> select * from t_x;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
+----+------+
3 rows in set (0.01 sec)
// 回滚到第一个保存点
mysql> rollback to a1;
Query OK, 0 rows affected (0.01 sec)
// 此时查询,只有第一个保存点时的一条数据
mysql> select * from t_x;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
+----+------+
1 row in set (0.00 sec)
// 尝试回滚到第二个保存点, 出错
mysql> rollback to a2;
1305 - SAVEPOINT a2 does not exist
mysql>
|