事务
- 事务简介
- 事务操作
- 事务四大特性
- 并发事务问题
- 事务隔离级别
事务是一组操作的集合,它是一个不可分割的工作单位,事务会把所有的操作作为一个整体一起向系统提交或撤销操作请求,即这些操作要么同时成功,要么同时失败。
create table account(
id int auto_increment primary key comment '主键ID',
name varchar(10) comment '姓名',
money int comment '余额'
) comment '账户表';
insert into account(id, name, money) VALUES (null, '张三', 2000), (null, '李四', 2000);
update account set money = 2000 where name = '张三' or name = '李四';
select @@autocommit;
set @@autocommit = 1;
select * from account where name = '张三';
update account set money = money - 1000 where name = '张三';
update account set money = money + 1000 where name = '李四';
commit ;
rollback ;
start transaction ;
select * from account where name = '张三';
update account set money = money - 1000 where name = '张三';
update account set money = money + 1000 where name = '李四';
commit ;
rollback ;
select @@transaction_isolation;
set session transaction isolation level read uncommitted;
set session transaction isolation level repeatable read ;
|