当前位置:网站首页>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
边栏推荐
- Click the input box to pop up the keyboard layout and move up
- Sentinel rule persistence into Nacos
- MVVM模型
- WebView opens H5 video and displays gray background or black triangle button. Problem solved
- ESP32 LVGL8. 1 - calendar (calendar 25)
- 7、 DOM (Part 2) - chapter after class exercises and answers
- Use of content provider
- K210串口通信
- Get a list of recent apps
- Methods of nested recycleview to solve sliding conflict and incomplete item display
猜你喜欢
listener. log
简化路径(力扣71)
The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
Excel intercept text
Iptables - L executes slowly
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
ESP32 LVGL8. 1 - textarea text area (textarea 26)
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
随机推荐
Esp32 (UART ecoh) - serial port echo worm learning (2)
Treatment of incomplete display of listview height
Can filter
[popular science] CRC verification (I) what is CRC verification?
Esp32 (UART event) - serial port event learning (1)
ESP32 LVGL8. 1 - calendar (calendar 25)
ESP32 LVGL8. 1 - bar progress bar (bar 21)
迁移学习进阶
22 year flying Book manpower Kit
STM32: LCD显示
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
ESP32 LVGL8. 1 - input devices (input devices 18)
Eight bit binary multiplier VHDL
Database computer experiment 4 (data integrity and stored procedure)
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
listener.log
Redis common interview questions
ESP32 LVGL8. 1 - event (event 17)
STM32: LCD display
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha