Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Transaction and try catch usage in SQL statement

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Ordinary SQL transactions: begin transaction tr declare @ error int; set @ error=0; select * from Car_Brand set @ error=@error+@@ERROR select 1 set @ error=@error+@@ERROR select * from AREA set @ error=@error+@@ERROR print'i have executable Set @ error=@error+@@ERROR print'@ @ error:'+cast (@ error as varchar (50)) if (@ error0) begin print 'executed failed'; rollback transaction tr end else begin print' executed success'; commit transaction tr end combined with try catch's SQL transaction: begin trybegin transaction tr select * from Car_Brand update car_log set [reason] = 'ceshiceshiceshi' where [modelid] = 557; select 1 gamma 0 print' I have executable' Select * from AREA print 'executed success'; commit transaction trend trybegin catch print' executed failed'; rollback transaction trend catch

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report