当前位置:网站首页>MySQL学习第五弹——事务及其操作特性详解
MySQL学习第五弹——事务及其操作特性详解
2022-04-23 18:49:00 【loveCC_orange】
事务
- 事务简介
- 事务操作
- 事务四大特性
- 并发事务问题
- 事务隔离级别
事务是一组操作的集合,它是一个不可分割的工作单位,事务会把所有的操作作为一个整体一起向系统提交或撤销操作请求,即这些操作要么同时成功,要么同时失败。






-- ---------------------------------事务操作-----------------------------------------
-- 数据准备
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; -- 设置为手动提交
-- 转账操作(张三给李四转1000)
-- 1.查询张三余额
select * from account where name = '张三';
-- 2、将张三余额减1000
update account set money = money - 1000 where name = '张三';
-- 3、将李四余额加1000
update account set money = money + 1000 where name = '李四';
-- 提交事务
commit ;
-- 回滚事务
rollback ;
-- 方式二
-- 转账操作(张三给李四转账1000)
start transaction ;
-- 1、查询张三余额
select * from account where name = '张三';
-- 2、将张三余额-1000
update account set money = money - 1000 where name = '张三';
-- 3、将李四余额+1000
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 ;
版权声明
本文为[loveCC_orange]所创,转载请带上原文链接,感谢
https://blog.csdn.net/loveCC_orange/article/details/124366754
边栏推荐
- Nacos集群搭建和mysql持久化配置
- ctfshow-web362(SSTI)
- Dynamically add and delete layouts
- c#:泛型反射
- ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
- Machine learning practice - naive Bayes
- Nacos作为服务配置中心实战
- 使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
- Nacos作为服务注册中心
- Ionic instruction set order from creation to packaging
猜你喜欢

从技术体系到商业洞察,中小研发团队架构实践之收尾篇

实战业务优化方案总结---主目录---持续更新

Introduction to ROS learning notes (II)

Kettle paoding jieniu Chapter 17 text file output

Practice of Druid SQL and security in meituan review

ESP32 LVGL8. 1 - img picture (IMG 20)

ESP32 LVGL8. 1 - roller rolling (roller 24)

After opening the original normal project, the dependency package displays red and does not exist.

玻璃体中的硫酸软骨素

The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
随机推荐
listener. log
【数学建模】—— 层次分析法(AHP)
MVVM模型
Sentinel规则持久化进Nacos
Fundamentals of machine learning theory -- some terms about machine learning
Query the logistics update quantity according to the express order number
Ucosiii transplantation and use, reference punctual atom
【科普】CRC校验(一)什么是CRC校验?
Introduction to QT programming
The type initializer for ‘Gdip‘ threw an exception
Loop path
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
Can filter
玻璃体中的硫酸软骨素
Use of kotlin collaboration in the project
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
Nacos作为服务注册中心
Ctfshow - web362 (ssti)
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
Golang 语言实现TCP UDP通信