事务引擎: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博客 ” ,链接:http://blog.itpub.net/24103417/viewspace-1415097/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24103417/viewspace-1415097/