当前位置:网站首页>MySQL-06
MySQL-06
2022-06-26 05:58:00 【Mr.Rop】
6、 Business
6.1、 What is business
Or both , Or they all failed
One by one
1、SQL perform A to B Transfer accounts A 1000 —>200 B 200
2、SQL perform B received A The money A 800 —> B 400
One by one
A set of SQL Put it in a batch to execute
Business principles :ACID principle Atomicity , Uniformity , Isolation, , persistence ( Dirty reading , Fantasy reading …)
Atomicity (Atomicity)
Either they all succeed , Or they all failed
Uniformity (Consistency)
The data integrity before and after the transaction should be consistent
persistence (Durability) – Transaction submission
Once the transaction is committed, it is irreversible , Be persisted to the database
Isolation, (Isolation)
Transaction isolation is when multiple users access the database concurrently , A transaction opened by a database for each user , Can't be disturbed by the operation data of other transactions , Multiple concurrent transactions should be isolated from each other .
Some of the problems caused by isolation
Dirty reading :
A transaction reads uncommitted data from another transaction .
It can't be read repeatedly :
Read a row of data in a table within a transaction , Multiple reads result is different .( This is not necessarily a mistake , It's just that on some occasions it's not right )
Virtual reading ( Fantasy reading ):
It refers to the data inserted by other transactions in a transaction , Leading to inconsistent reading before and after .
( It's usually the line effect , One more line )
Perform transactions
-- ========== Business =============
-- mysql The default transaction is auto commit
SET autocommit =0 /* close */
SET autocommit =1 /* Turn on ( default ) */
-- Handle transactions manually
SET autocommit =0 -- Turn off auto submit
-- The transaction open
START TRANSACTION -- Mark the beginning of a transaction , After this SQL All in the same transaction
-- Submit : Persistence ( success !)
COMMIT
-- Roll back : Return to the original ( Failure !)
ROLLBACK
-- End of transaction
SET autocommit =1 -- Turn on auto submit
-- understand
SAVEPOINT Save roll call -- Set a save point for a transaction
ROLLBACK TO SAVEPOINT Save roll call -- Roll back to savepoint
RELEASE SAVEPOINT Save roll call -- Undo savepoint
Simulation scenario
-- ========== Business =============
-- Analog transfer
-- Create database
CREATE DATABASE shop CHARACTER SET utf8 COLLATE utf8_general_ci
USE shop
-- Create table
CREATE TABLE `account`(
`id` INT(3) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(30) NOT NULL,
`money` DECIMAL(9,2) NOT NULL,
PRIMARY KEY (`id`)
)ENGINE=INNODB DEFAULT CHARSET=utf8
-- Add data
INSERT INTO account(`name`,`money`)
VALUES('A',2000.00),('B',10000.00)
-- Analog transfer , Business
SET autocommit =0 -- Turn off auto submit
START TRANSACTION -- Start a transaction ( A set of transactions )
UPDATE account SET money=money-500 WHERE `name`='A' -- A reduce 500
UPDATE account SET money=money+500 WHERE `name`='B' -- B Add 500
COMMIT; -- Commit transaction
ROLLBACK; -- Roll back
SET autocommit = 1; -- Restore defaults
边栏推荐
猜你喜欢

Factory method pattern, abstract factory pattern

Overloading and overriding

Unicloud cloud development obtains applet user openid

Bubble sort

421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)

Test depends on abstraction and does not depend on concrete

Bingc (inheritance)

小程序如何关联微信小程序二维码,实现二码聚合

kolla-ansible部署openstack yoga版本

冒泡排序(Bubble Sort)
随机推荐
Func < T, tresult > Commission - learning record
冒泡排序(Bubble Sort)
花生壳内网穿透映射NPM私服问题
状态模式,身随心变
Level signal and differential signal
Spark source code analysis (I): RDD collection data - partition data allocation
Machine learning 05: nonlinear support vector machines
A new explanation of tcp/ip five layer protocol model
Project suspension
原型模式,咩咩乱叫
机器学习 05:非线性支持向量机
Redis underlying data structure
机器学习 07:PCA 及其 sklearn 源码解读
Gram 矩阵
Easy to understand from the IDE, and then talk about the applet IDE
自定义WebSerivce作为代理解决SilverLight跨域调用WebService问题
家庭记账程序(第一版)
虚拟项目失败感想
Selective Search for Object Recognition 论文笔记【图片目标分割】
[C language] deep analysis of data storage in memory