ITPub博客

首页 > 数据库 > MySQL > 36、事务语法

36、事务语法

原创 MySQL 作者:cxmfyl 时间:2015-01-26 08:55:54 0 删除 编辑
事务引擎:innodb /  bdb 
开启事务:
start transaction;
update account set money = money + 500 where id =2;
update account set money = money - 500 where id = 1;
commit;    #提交事务

注意:当一个事务commit或者rollback之后,这个事务就结束了,下次需要使用事务,还要执行start transaction;

start transaction;
update account set money = money + 5000  where id = 2;
update account set money = money - 5000  where ids = 1;  //出现错误
rollback;        //回滚操作,撤销上面更新操作

影响事务的语句:(隐式提交)
    新发起一个事务  start transaction;  会将上一个事务提交。

事务的基本原理:
     开启事务之后,事务中的sql语句影响的是事务日志文件,而非表数据文件,一旦事务提交,事务日志再集中作用到表数据文件进行更新操作。

1.选用innodb
2.使用start transaction开始
3.使用commit或rollback结束







来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24103417/viewspace-1415097/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-01-26

  • 博文量
    5
  • 访问量
    4662