当前位置:网站首页>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
边栏推荐
- 開關電源設計分享及電源設計技巧圖解
- Network protocol: SCTP flow control transmission protocol
- mysql_linux版本的下載及安裝詳解
- The type initializer for ‘Gdip‘ threw an exception
- [record] typeerror: this getOptions is not a function
- Dynamically add and delete layouts
- ESP32 LVGL8. 1 - bar progress bar (bar 21)
- mysql_ Download and installation of Linux version
- How can programmers quickly develop high-quality code?
- MySQL学习第五弹——事务及其操作特性详解
猜你喜欢
[advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
Simplified path (force buckle 71)
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
ESP32 LVGL8. 1 - input devices (input devices 18)
微搭低代码零基础入门课(第三课)
Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
2022.04.23(LC_763_划分字母区间)
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
ESP32 LVGL8. 1 - arc (arc 19)
Installation, use and problem summary of binlog2sql tool
随机推荐
How can programmers quickly develop high-quality code?
Nacos cluster construction and MySQL persistence configuration
SSDB foundation 1
SSDB基础3
How about CICC wealth? Is it safe to open an account up there
Seata handles distributed transactions
【C语言进阶11——字符和字符串函数及其模拟实现(2))】
SSDB foundation 2
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
Keysight has chosen what equipment to buy for you
The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics
mysql_linux版本的下载及安装详解
After opening the original normal project, the dependency package displays red and does not exist.
浅谈c语言指针的强制转换
Summary of actual business optimization scheme - main directory - continuous update
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
About the operation of unit file reading (I)
SSDB Foundation
Sentinel规则持久化进Nacos
The type initializer for ‘Gdip‘ threw an exception