当前位置:网站首页>SQL transaction
SQL transaction
2022-07-21 03:42:00 【Superman moving forward】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
Catalog
3、 ... and 、 Transaction control statement
Four 、 Transaction processing method
Preface
This is about SQL Articles on business
Tips : The following is the main body of this article , The following cases can be used for reference
One 、SQL Business
MySQL Transactions are mainly used to handle large amount of operations , Data with high complexity . for instance , In the people management system , You delete a person , You need to delete the basic information of the personnel , Also delete information related to the person , Such as mailbox , Articles, etc , such , These database operation statements constitute a transaction !
- stay MySQL Only use Innodb The database or table of the database engine supports transactions .
- Transactions can be used to maintain database integrity , Make sure that there are lots of SQL Statement or all execution , Or none at all .
- Affairs are used to manage insert , update , delete sentence .
Two 、 features
Generally speaking , Transactions must be satisfied 4 Conditions (ACID): Atomicity( Atomicity or indivisibility )、Consistency( Uniformity )、Isolation( Isolation or independence )、Durability( persistence )
- 1、 Atomicity :** A set of transactions , Or success ; Or withdraw , That is, if an error occurs during the execution of a transaction, it will be rolled back to the state before the start of the transaction .
- 2、 Uniformity : A transaction, whether before or after the beginning , The integrity of the database has not been destroyed . Therefore, the written data must fully comply with all preset rules ( Data accuracy 、 Serialization and subsequent databases can spontaneously complete the scheduled work ).
- 3、 Isolation, :** The database allows multiple transactions to read, write and modify its data simultaneously , Isolation can prevent data inconsistency caused by cross execution when multiple transactions are executed concurrently . Transaction isolation can be divided into :Read uncommitted( Read uncommitted )、Read committed( Read the submission )、Repeatable read( Repeatable )、Serializable( Serialization ).
- 4、 persistence :** The changes made to the data after the transaction is completed are permanent , Cannot lose .
3、 ... and 、 Transaction control statement
1, Start a transaction explicitly
start transaction
perhaps
begin
2, Make a save point , There can be multiple savepoints in a transaction
savepoint Save point name
3, Commit transaction , And make all changes made in the database permanent
commit
perhaps
commit work
4, Rollback ends the user's transaction , And undo all pending changes
rollback
perhaps
rollback work
5. Delete a transaction savepoint , If no save point is specified , Executing this statement will throw an error
release savepoint Save point name
6. Roll the transaction back to the marked point
rollback to Marker points
7. Set the isolation level of the transaction .InnoDB The isolation levels that the storage engine provides for transactions are READ UNCOMMITTED、READ COMMITTED、REPEATABLE READ and SERIALIZABLE
set transaction
Four 、 Transaction processing method
1. use begin , rollback , commit To implement transactions .
2. use set To change MySQL The auto submit mode of .
- set autocommit = OFF ( Disable auto submit ).
- set autocommit = ON ( Turn on auto submit ).
5、 ... and 、 example
-- Turn off auto submit
SET autocommit = OFF;
SHOW VARIABLES LIKE 'autocommit';
-- Open transaction ( A set of transactions )
START TRANSACTION;
UPDATE shop SET money = money + 500 WHERE NAME = 'A';
UPDATE shop SET money = money + 10000 WHERE NAME = 'B';
COMMIT; -- Commit transaction Once submitted, it is persisted
ROLLBACK; -- Roll back
SET autocommit = on; -- Restore defaults
边栏推荐
- MIMO - OFDM Wireless Communication Technology and matlab Implementation (2) - outdoor Channel Model under SISO
- Li Hongyi machine learning 2020---p12 brief introduction of DL & p15 why DL
- Paper study -- resource allocation for multi user downlink miso OFDMA urllc systems
- (六)PyTorch深度学习:Logistic回归(多层多维特征输入)
- xcode编译 build号自增
- Dameng AWR report extraction
- MIMO-OFDM無線通信技術及MATLAB實現(2)-SISO下的室外信道模型
- Basic architecture of data warehouse -- layered functions
- (九)PyTorch深度学习:卷积神经网络( GoogleNet网络架构中的 inception module 模块为本次卷积神经网络架构)
- Data Lake definition
猜你喜欢
【CANN训练营】CANN训练营_昇腾AI趣味应用实现AI趣味应用(下)随笔
Hyperledger fabric super ledger CA construction and use
玩转CANN目标检测与识别一站式方案【基础篇】
基于昇腾AI异构计算架构CANN的通用目标检测与识别一站式方案初体验
Centos8 (Linux) 安装 redis
(六)PyTorch深度学习:Logistic回归(多层多维特征输入)
【深度学习】运用mnist数据集实例化一个简单的卷积神经网络
Paper study -- resource allocation and beamforming desing in the short blocklength region for urllc
昇腾工业质检应用实战
【CANN訓練營】基於昇思的GAN實現隨筆
随机推荐
Paper learning -- resource allocation in EE urllc in relay system
根据不同configuration加载不同的plist文件
Paper study -- resource allocation and beamforming desing in the short blocklength region for urllc
SQL子查询
Swift Archiving序列化
基于点云的深度学习方法综述
Flink SQL custom parsing map and array data types
基于昇腾AI异构计算架构CANN的通用目标检测与识别一站式方案初体验
Opencv系列教程(一):Opencv读取指定文件夹图片、视频,调用摄像头
Endnote x9 import journal reference format of paper submission
(三)PyTorch深度学习:反向传播梯度下降
达梦免密登录
Mysql 主从复制 docker集群搭建
EndNote X9导入论文投稿的期刊参考文献格式
论文学习----URLLC benefit from NOMA (1)
【CANN训练营】CANN训练营_昇腾AI趣味应用实现AI趣味应用(上)随笔
【CANN训练营】基于昇腾CANN平台的AI CPU算子开发
Redis persistence
(七)PyTorch深度学习:全连接层网络
(六)PyTorch深度学习:Logistic回归(多层多维特征输入)