1. 什么叫做事务?

2.默认情况下每一条sql语句都是一个事务,然后自动提交事务  ps:如果想多条语句占一个事务,则可以手动设置SetAutoCommit为false

3.关键字 start transaction;rollback;commit

  3.1 练习 创建account表(id,name,money),插入两条数据(a,b);start transaction;set a+100,set b-100;commit rollback  

create table account(
id int primary key auto_increment,
name varchar(20),
money double  //在MySQL中没有money类型
);  
insert into account values(null,'a',1000),(null,'b',1000)
start transaction
update account set money = money -100 where name='a';
update account set money = money +100 where name='b';
commit;
View Code

相关文章:

  • 2021-07-02
  • 2021-09-28
  • 2022-12-23
  • 2021-06-10
  • 2022-02-24
  • 2021-05-24
猜你喜欢
  • 2021-11-02
  • 2021-10-17
  • 2021-10-15
  • 2021-07-14
  • 2021-04-20
  • 2022-02-21
相关资源
相似解决方案