说明

如果不设置回滚点,如果回滚,直接回滚到事务开始前,有时我们只需要回滚到中间的某个位置,就可以设置回滚点
语法

回滚点的操作语句 语句
设置回滚点 savepoint 名字
回到回滚点 rollback to 名字

例子

  1. -- 开启事务
  2. start transaction;
  3. -- a用户先减100
  4. update account set money = money - 100 where name = 'a';
  5. -- 设置回滚点
  6. savepoint itcast;
  7. -- a用户再次减100
  8. update account set money = money - 100 where name = 'a';
  9. -- 回到回滚点
  10. rollback to itcast;
  11. -- 提交事务
  12. commit;