SET XACT_ABORT ON
来源:互联网 发布:进销存系统数据库设计 编辑:程序博客网 时间:2024/05/20 21:46
SET XACT_ABORT ON这个语句经常与事务连用,当这个设置为ON的时候,后面的事务片段中的语句只要有一个错误,在事务提交的时候,系统自动检测到该事务中有出错的语句,并在SET XACT_ABORT ON的作用下,自动回滚整个事务中的数据操作。但是如果把SET XACT_ABORT ON与try catch连用的时候,注意应手工设置事务回滚,比如:
begin trySET XACT_ABORT ONbegin tran --开始执行事务 --update comment 1,minus in AWupdate TUserProperty set treasure=0 where userid=@AWUserId;--update comment 2,plus in HNupdate web_users set jewels=@JewelsBeforeHN+@JewelsBeforeAW where userid=@HNUserId;commit tranend try begin catchROLLBACK TRAN set @ReturnValue=6;end catch
当在事务中检测到错误的时候,try中的后续语句就不会再继续执行了(经过调试发现,即使try中用的是begin tran commit tran 片段,出错后面的语句也不会继续执行,所以必须手工回滚!),就会end try并begin catch,由于上文中的事务一直由于错误而挂起,那么必须手工rollback tran
但是单独使用SET XACT_ABORT ON及begin tran 及 commit tran (即不与try catch一起用),将自动回滚事务
0 0
- SET XACT_ABORT { ON | OFF }
- SET XACT_ABORT ON
- SET XACT_ABORT ON
- SET XACT_ABORT ON
- 数据库事物用法 SET XACT_ABORT ON
- SQL Server 的 SET XACT_ABORT ON | OFF;
- SET XACT_ABORT
- SET XACT_ABORT
- SET XACT_ABORT
- SET XACT_ABORT
- SET XACT_ABORT
- SET XACT_ABORT
- 在存储过程中SET XACT_ABORT ON 有什么用
- 存储过程中的 SET XACT_ABORT ON 和事务
- set XACT_ABORT ON与判断事务的异同
- SET XACT_ABORT 的用法
- SET XACT_ABORT 的用法
- SET XACT_ABORT的用法
- 地图开发专家Blog
- 四组对象和级联
- 利用soot插装Android App
- ubifs文件系统制作
- 单调递减队列
- SET XACT_ABORT ON
- 新计划
- 怎么用网盘查找资源
- Chapter 9: Mixture Models and EM
- TIJ_字符串
- LCD 调试问题总结
- 不同根视图下控制部分屏幕旋转(tabbarController/navigationController)
- 337. House Robber III
- STM32F105的时钟配置