下表 c1,开始一个事务块,有两个保存点 s1 & s2。我们回滚了 s2 之后的所有操作,并且提交了 s2 之前的所有操作,此时 s1 & s2 已经失效。那记录数刚好两条。{"db":"ytt"},"port":"3320"}-mysql>truncate c1;
Query OK, 0 rows affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>
{"db":"ytt"},"port":"3320"}-mysql>
{"db":"ytt"},"port":"3320"}-mysql>use ytt
Database changed
{"db":"ytt"},"port":"3320"}-mysql>begin;
Query OK, 0 rows affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>insert into c1 values (1,20,now());
Query OK, 1 row affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>savepoint s1;
Query OK, 0 rows affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>insert into c1 values (2,30,now());
Query OK, 1 row affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>savepoint s2;
Query OK, 0 rows affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>insert into c1 values (3,40,now());
Query OK, 1 row affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>rollback to savepoint s2;
Query OK, 0 rows affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>commit;
Query OK, 0 rows affected (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>select * from c1;
+----+------+---------------------+
| id | c1 | c2 |
+----+------+---------------------+
| 1 | 20 | 2019-12-02 10:07:02 |
| 2 | 30 | 2019-12-02 10:07:12 |
+----+------+---------------------+
2 rows in set (0.00 sec)
{"db":"ytt"},"port":"3320"}-mysql>