当前位置:网站首页>SQL transaction
SQL transaction
2022-07-02 15:27:00 【slb190623】
What is business
Business : David and Jonathan
A program execution unit that accesses and may update various data items in a database (unit), That is, by multiple sql Sentence composition , It must be implemented as a whole A C I D
these sql Statements are submitted to the system as a whole , Or both , Either not ; Transactions are about the possibility of changing table data – Additions and deletions , It's no use to query
Business characteristics :CUID
1. Atomicity : Affairs cannot be further divided , Transaction must be atomic unit of work ; For other data modification , Or all , Either not
2. Uniformity : After transaction , The data needs to be consistent to some extent
3. Isolation, : Each transaction is independent , Not affected by other transactions
4. persistence : Once the transaction is committed , Modifications to data are permanently retained
How to use transactions : Include the add, delete and modify commands you execute between the start and commit of the transaction or the start and rollback .
Grammatical steps :
Start business :BEGIN TRANSACTION -- Open transaction
Transaction submission :COMMIT TRANSACTION -- Submit operation
Transaction rollback :ROLLBACK TRANSACTION -- Cancel operation
Judge whether there is an error in the execution of a statement :
Global variables @@ERROR;
@@ERROR You can only judge the current one T-SQL Statement execution error , In order to determine all of the T-SQL Is there an error in the statement , We need to accumulate errors ;
for example :SET @errorSum = @errorSum + @@ERROR
requirement :–aa turn 1000 Yuan to bb(cmoney The fields are done check constraint >=1)
declare @cuowuhao int = 0 -- Record the error number that may occur during the execution of the statement
begin transaction
update bank set cmoney = cmoney - 1000 where name = 'aa'
set @cuowuhao = @cuowuhao + @@ERROR -- Just add up an error number
update bank set cmoney = cmoney + 1000 where name = 'bb'
set @cuowuhao += @@ERROR
select * from bank
if(@cuowuhao<>0) -- Erroneous , Only after all the statements are executed , Then make an overall judgment
rollback transaction
else
commit transaction
select * from bank
go
result :
边栏推荐
- Mavn 搭建 Nexus 私服
- Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
- 03_线性表_链表
- Real estate market trend outlook in 2022
- Pytorch 保存tensor到.mat文件
- 20_Redis_哨兵模式
- yolo格式数据集处理(xml转txt)
- . Solution to the problem of Chinese garbled code when net core reads files
- 做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统
- Libcurl Lesson 13 static library introduces OpenSSL compilation dependency
猜你喜欢
N皇后问题的解决
17_Redis_Redis发布订阅
FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA
学习使用php将时间戳转换为大写日期的方法代码示例
Semantic segmentation learning notes (1)
Map介绍
Evaluation of embedded rz/g2l processor core board and development board of Feiling
语义分割学习笔记(一)
LeetCode刷题——去除重复字母#316#Medium
FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
随机推荐
Common English abbreviations for data analysis (I)
20_Redis_哨兵模式
Map introduction
JVM architecture, classloader, parental delegation mechanism
Markdown tutorial
03.golang初步使用
Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
The past and present lives of visual page building tools
Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
XML配置文件
让您的HMI更具优势,FET-G2LD-C核心板是个好选择
学习使用php实现公历农历转换的方法代码
QML pop-up frame, customizable
16_Redis_Redis持久化
Download blender on Alibaba cloud image station
17_ Redis_ Redis publish subscription
08_ 串
数据分析常见的英文缩写(一)
Yolov5 code reproduction and server operation