当前位置:网站首页>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 :
边栏推荐
猜你喜欢
YOLOV5 代码复现以及搭载服务器运行
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
21_ Redis_ Analysis of redis cache penetration and avalanche
MySQL -- Index Optimization -- order by
【网络安全】网络资产收集
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
Set set you don't know
Pytorch 保存tensor到.mat文件
19_ Redis_ Manually configure the host after downtime
随机推荐
21_ Redis_ Analysis of redis cache penetration and avalanche
04.进入云原生后的企业级应用构建的一些思考
There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
13_Redis_事务
Mavn 搭建 Nexus 私服
XML配置文件
AtCoder Beginner Contest 254
TiDB 集群最小部署的拓扑架构
.NET Core 日志系统
php获取数组中键值最大数组项的索引值的方法
List集合&UML图
记一次面试
How to conduct TPC-C test on tidb
05_ queue
Deploy tidb cluster with tiup
Guangzhou Emergency Management Bureau issued a high temperature and high humidity chemical safety reminder in July
你不知道的Set集合
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
损失函数与正负样本分配:YOLO系列
Points clés de l'examen de principe de compilation pour l'année scolaire 2021 - 2022 [Université chinoise d'outre - mer]