一、事务
1、转账
- sql:建表
create database day16; use day16; create table account( id int primary key auto_increment, name varchar(40), money float )character set utf8 collate utf8_general_ci; insert into account(name,money) values('aaa',1000); insert into account(name,money) values('bbb',1000); insert into account(name,money) values('ccc',1000);
- sql:开启事务,回滚事务,提交事务(如果没有收到commit,会自动回滚。回滚就是回滚到事务开始之前)
start transaction; update account set money=money-100 where name="aaa"; update account set money=money+100 where name="bbb"; commit;
- sql:手动回滚(自动回滚,就是关掉对话框)
start transaction; update account set money=money-100 where name="aaa"; rollback; commit;