当前位置:网站首页>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
边栏推荐
- 【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
- ESP32 LVGL8. 1 - textarea text area (textarea 26)
- Redis common interview questions
- 为何PostgreSQL即将超越SQL Server?
- Openharmony open source developer growth plan, looking for new open source forces that change the world!
- MVVM model
- [today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
- Download xshell 6 and xftp6 official websites
- Keysight has chosen what equipment to buy for you
- Practice of Druid SQL and security in meituan review
猜你喜欢
ESP32 LVGL8. 1 - textarea text area (textarea 26)
MySQL学习第五弹——事务及其操作特性详解
为何PostgreSQL即将超越SQL Server?
Simple use of navigation in jetpack
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
Using Visual Studio code to develop Arduino
Eight bit binary multiplier VHDL
Getting started with vcpkg
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
ESP32 LVGL8. 1 - roller rolling (roller 24)
随机推荐
Scrollto and scrollby
After opening the original normal project, the dependency package displays red and does not exist.
Nacos集群搭建和mysql持久化配置
ESP32 LVGL8. 1 - input devices (input devices 18)
Druid SQL和Security在美团点评的实践
Wechat applet part of the mobile phone Preview PDF did not respond
WebView opens H5 video and displays gray background or black triangle button. Problem solved
Disable Ctrl + Alt + Del
SSDB基础2
c1000k TCP 连接上限测试1
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
SSDB foundation 3
中金财富怎么样?在上边开户安全吗
MySQL statement
12 examples to consolidate promise Foundation
简化路径(力扣71)
On the forced conversion of C language pointer
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
std::stoi stol stoul stoll stof stod