在MySQL中,事务提交与回滚
对t_act进行提交和回滚操作
(1).提交操作(非事务成功)
update t_act set balance=400 where actno=1;
update t_act set balance=200 where actno=2;

(2).提交操作(非事务失败)
update t_act set balance=400 where actno=1;
update t_act set balance=200 where actno=2 w;

(3).提交操作(事务成功)
- start transaction #开始事务
- DML语句
- commit #事务提交
start transaction;#手动开启事务
update t_act set balance=400 where actno=1;
update t_act set balance=200 where actno=2;
commit;#commit之后即可改变底层数据库数据

(4).提交操作(事务失败)
start transaction;#手动开启事务
update t_act set balance=400 where actno=1;
update t_act set balance=200 where actno=2w; #这个地方故意让第二个语句出错
commit;#commit之后即可改变底层数据库数据

(5)回滚操作(事务失败)
回滚操作指的是当我们事务提交失败的时候,就需要我们将数据回滚到失败前的时间段
比如,delete一张表,忘加限制条件,整张表没了。
误操作后,能快速回滚数据是非常重要的。
- start transaction
- DML语句
- rollback
start transaction;#手动开启事务
delete from t_act;
rollback;








![[附源码]JAVA毕业设计高校智能排课系统(系统+LW)](https://img-blog.csdnimg.cn/880302af841b47af92df7b388dd2ff77.png)









![[附源码]Python计算机毕业设计Django二次元信息分享平台的设计及实现](https://img-blog.csdnimg.cn/ceff51a9d2b549e690789410cb254629.png)