当前位置:网站首页>Transaction processing of SQL Server database
Transaction processing of SQL Server database
2022-04-23 19:08:00 【Little brother】
SQL Server There are two main ways to write the transaction processing of database :
The first one is :
begin transaction -- Open transaction
DECLARE @i INT; -- Define a variable i
set @i=0; -- Give the variable an initial value
insert into TB_Salesman values ('SM007',' Li ling ',' Woman ','D003',' Level seven ');
set @[email protected][email protected]@ERROR
insert into TB_Salesman values ('SM006',' Li ling ',' Woman ','D003',' Level seven ');
set @[email protected][email protected]@ERROR
if(@i>0)
begin
rollback tran;-- Transaction rollback
print ' operation failed '
end
else
begin
commit tran;-- Transaction submission
print ' Successful operation '
end
GO
The second kind : Use try catch
begin transaction -- Open transaction
DECLARE @i INT; -- Define a variable i
set @i=0; -- Give the variable an initial value
begin try
insert into TB_Salesman values ('SM008',' Li ling ',' Woman ','D003',' Level seven ');
insert into TB_Salesman values ('SM009',' Li ling ',' Woman ','D003',' Level seven ');
end try
begin catch
set @[email protected]+1; -- It can be executed normally with or without a plus sign
end catch
if(@i>0)
begin
rollback tran; -- Transaction rollback
print ' In the wrong ';
end
else
begin
commit tran; -- Transaction submission
print 'OK';
end
GO
版权声明
本文为[Little brother]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210601422883.html
边栏推荐
- RPM package management
- Zlib realizes streaming decompression
- Sentinel rule persistence into Nacos
- Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
- ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
- From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
- C1000k TCP connection upper limit test 1
- 2022.04.23(LC_714_买卖股票的最佳时机含手续费)
- SSDB基础
- C1000k TCP connection upper limit test
猜你喜欢

Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)

MySQL学习第五弹——事务及其操作特性详解
![[record] typeerror: this getOptions is not a function](/img/c9/0d92891b6beec3d6085bd3da516f00.png)
[record] typeerror: this getOptions is not a function

ESP32 LVGL8. 1 - input devices (input devices 18)

Introduction to ROS learning notes (II)

剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)

From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure

2022.04.23(LC_714_买卖股票的最佳时机含手续费)

ESP32 LVGL8. 1 - checkbox (checkbox 23)

2022.04.23 (lc_763_divided into letter interval)
随机推荐
Redis optimization series (III) solve common problems after master-slave configuration
ESP32 LVGL8. 1 - textarea text area (textarea 26)
Simplified path (force buckle 71)
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
Introduction to ROS learning notes (II)
C1000k TCP connection upper limit test 1
网络协议之:sctp流控制传输协议
简化路径(力扣71)
【玩转Lighthouse】腾讯云轻量服务器搭建全平台视频解析视频下载网站
MySQL Téléchargement et installation de la version Linux
ESP32 LVGL8. 1 - roller rolling (roller 24)
7、 DOM (Part 2) - chapter after class exercises and answers
Sentinel rule persistence into Nacos
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
Switching power supply design sharing and power supply design skills diagram
Codeforces Round #784 (Div. 4)
Use of content provider
std::stoi stol stoul stoll stof stod
2022.04.23(LC_763_划分字母区间)
ESP32 LVGL8. 1 - checkbox (checkbox 23)