当前位置:网站首页>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 :
边栏推荐
- Infra11199 database system
- JVM architecture, classloader, parental delegation mechanism
- Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
- Mavn 搭建 Nexus 私服
- Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
- . Net core logging system
- How to choose a third-party software testing organization for automated acceptance testing of mobile applications
- Tidb environment and system configuration check
- Build your own semantic segmentation platform deeplabv3+
- 做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统
猜你喜欢

CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E

Case introduction and problem analysis of microservice

YOLOV5 代码复现以及搭载服务器运行

LeetCode刷题——统计各位数字都不同的数字个数#357#Medium

Map introduction

vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)

Mavn builds nexus private server

18_Redis_Redis主从复制&&集群搭建

03_線性錶_鏈錶

Learn the method code example of converting timestamp to uppercase date using PHP
随机推荐
基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
Semantic segmentation learning notes (1)
04_ Stack
Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
Recommended configuration of tidb software and hardware environment
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
JVM architecture, classloader, parental delegation mechanism
6.12 企业内部upp平台(Unified Process Platform)的关键一刻
面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
02_线性表_顺序表
搭载TI AM62x处理器,飞凌FET6254-C核心板首发上市!
Mavn 搭建 Nexus 私服
搭建自己的语义分割平台deeplabV3+
. Net again! Happy 20th birthday
CDN 在游戏领域的应用
使用 TiUP 部署 TiDB 集群
14_ Redis_ Optimistic lock
Solve the problem of frequent interruption of mobaxterm remote connection
12_Redis_Bitmap_命令
2021-2022学年编译原理考试重点[华侨大学]