当前位置:网站首页>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
边栏推荐
- CANopen STM32 transplantation
- Esp32 (UART 485 communication) - 485 communication of serial port (3)
- os_ authent_ Prefix
- STM32: LCD显示
- Simple use of navigation in jetpack
- Ctfshow - web362 (ssti)
- Practice of Druid SQL and security in meituan review
- ESP32 LVGL8. 1 - calendar (calendar 25)
- Advanced transfer learning
- 解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
猜你喜欢
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
教你用简单几个步骤快速重命名文件夹名
ESP32 LVGL8. 1 - textarea text area (textarea 26)
ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
机器学习实战 -朴素贝叶斯
12个例子夯实promise基础
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
os_authent_prefix
c#:泛型反射
随机推荐
Nacos作为服务注册中心
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
Machine learning theory (8): model integration ensemble learning
配置iptables
Daily CISSP certification common mistakes (April 19, 2022)
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
Golang 语言实现TCP UDP通信
22年字节跳动飞书人力套件三面面经
视频边框背景如何虚化,简单操作几步实现
Treatment of incomplete display of listview height
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Iptables - L executes slowly
WebView saves the last browsing location
Esp32 (UART ecoh) - serial port echo worm learning (2)
ESP32 LVGL8. 1 - label (style 14)
Kettle paoding jieniu Chapter 17 text file output
After opening the original normal project, the dependency package displays red and does not exist.
Daily network security certification test questions (April 13, 2022)
关于unity文件读取的操作(一)
Actual combat of Nacos as service configuration center