加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

Sqlserver 中使用事务的举例

发布时间:2020-12-12 14:07:00 所属栏目:MsSql教程 来源:网络整理
导读:--使用事务 begin transaction declare @error int set @error = 0 update bank set balance=balance-1000 where cid='0001' set @error = @error + @@error update bank set balance=balance + 1000 where cid='0002' set @error = @error + @@error if @er
--使用事务 begin transaction declare @error int set @error = 0 update bank set balance=balance-1000 where cid='0001' set @error = @error + @@error update bank set balance=balance + 1000 where cid='0002' set @error = @error + @@error if @error != 0 ?? ?rollback transaction else ?? ?commit transaction go select * from bank 举例2??? --还可以使用try catch的方式 begin transaction begin try ?? ?update bank set balance=balance-1000 where cid='0001' ?? ?update bank set balance=balance + 1000 where cid='0002' ?? ?commit transaction end try begin catch ?? ?rollback transaction end catch go select * from bank

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读