当前位置:网站首页>The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics
The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics
2022-04-23 18:54:00 【loveCC_ orange】
Business
- Business profile
- The transaction operations
- Four characteristics of transaction
- Concurrent transaction problems
- Transaction isolation level
A transaction is a collection of operations , It is an indivisible unit of work , The transaction will submit or revoke the operation request to the system as a whole , That is, these operations either succeed at the same time , Or fail at the same time .
-- --------------------------------- The transaction operations -----------------------------------------
-- Data preparation
create table account(
id int auto_increment primary key comment ' Primary key ID',
name varchar(10) comment ' full name ',
money int comment ' balance '
) comment ' Account form ';
insert into account(id, name, money) VALUES (null, ' Zhang San ', 2000), (null, ' Li Si ', 2000);
-- Restore data
update account set money = 2000 where name = ' Zhang San ' or name = ' Li Si ';
select @@autocommit;
set @@autocommit = 1; -- Set to manual submit
-- Transfer operation ( Zhang San gives Li sizhuan 1000)
-- 1. Check the balance of Zhang San
select * from account where name = ' Zhang San ';
-- 2、 Reduce the balance of Zhang San by 1000
update account set money = money - 1000 where name = ' Zhang San ';
-- 3、 Add... To the balance of Li Si 1000
update account set money = money + 1000 where name = ' Li Si ';
-- Commit transaction
commit ;
-- Roll back the transaction
rollback ;
-- Mode two
-- Transfer operation ( Zhang San transfers money to Li Si 1000)
start transaction ;
-- 1、 Check the balance of Zhang San
select * from account where name = ' Zhang San ';
-- 2、 Leave three balances -1000
update account set money = money - 1000 where name = ' Zhang San ';
-- 3、 Balance of Li Si +1000
update account set money = money + 1000 where name = ' Li Si ';
-- Commit transaction
commit ;
-- Roll back the transaction
rollback ;
-- Four characteristics of transactions
-- Atomicity
-- Uniformity
-- Isolation,
-- persistence
-- Concurrent transaction problems
-- The isolation level of the transaction
-- View transaction isolation level
select @@transaction_isolation;
-- Set the transaction isolation level
set session transaction isolation level read uncommitted;
set session transaction isolation level repeatable read ;
版权声明
本文为[loveCC_ orange]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231849152791.html
边栏推荐
猜你喜欢
12 examples to consolidate promise Foundation
Esp32 (UART 485 communication) - 485 communication of serial port (3)
mysql_ Download and installation of Linux version
Tangle
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
MySQL Téléchargement et installation de la version Linux
After opening the original normal project, the dependency package displays red and does not exist.
Esp01s with Arduino development environment
os_authent_prefix
Introduction to micro build low code zero Foundation (lesson 3)
随机推荐
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
Machine learning theory (8): model integration ensemble learning
Disable Ctrl + Alt + Del
Practice of Druid SQL and security in meituan review
Deeply understand what new and make in golang are and what are the differences?
Implementation of TCP UDP communication with golang language
The type initializer for ‘Gdip‘ threw an exception
Simple use of navigation in jetpack
Database computer experiment 4 (data integrity and stored procedure)
After opening the original normal project, the dependency package displays red and does not exist.
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
[mathematical modeling] - analytic hierarchy process (AHP)
ctfshow-web362(SSTI)
Machine learning practice - naive Bayes
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
ctfshow-web362(SSTI)
Druid SQL和Security在美团点评的实践
How about CICC wealth? Is it safe to open an account up there
Chondroitin sulfate in vitreous
How to virtualize the video frame and background is realized in a few simple steps