如果提交t2然后t1回滚,如何解决SQL trasactions提交和回滚问题? [英] How do I solve SQL trasactions commit and rollback issues if t2 is commited and then t1 is rollback ?

查看:106
本文介绍了如果提交t2然后t1回滚,如何解决SQL trasactions提交和回滚问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。开始T1交易



2.开始T2交易



3.通过T1将值10分配给成本列。所以成本= 10



4.通过T2将成本值更新为20。所以费用= 20



5.提交T2



6.回滚T1 ??这里的成本价值是20而不是10如何解决这个问题??????



我尝试过的事情:



没试过任何东西,因为我没有想到解决这个问题

1. Begin T1 Transaction

2. Begin T2 Transaction

3. assign value 10 to cost column by T1. so cost=10

4. Update cost value to 20 by T2. so cost=20

5. Commit T2

6. rollback T1 ?? here cost value is 20 only not 10 how to solve this issue??????

What I have tried:

not tried any thing because I am not getting idea to solve this

推荐答案

看看这个:嵌套交易 [ ^ ]



Look at this: Nesting Transactions[^]

Quote:

SQL Server数据库引擎会忽略提交内部事务。根据最外层事务结束时采取的操作,提交或回滚事务。如果提交了外部事务,则还会提交内部嵌套事务。如果外部事务被回滚,那么所有内部事务也会回滚,无论内部事务是否单独提交。

Committing inner transactions is ignored by the SQL Server Database Engine. The transaction is either committed or rolled back based on the action taken at the end of the outermost transaction. If the outer transaction is committed, the inner nested transactions are also committed. If the outer transaction is rolled back, then all inner transactions are also rolled back, regardless of whether or not the inner transactions were individually committed.





你需要手动检查事务计数并正确运行:异常处理和嵌套事务 [ ^ ]应该有所帮助。



You need to manually check the transaction count and behave appropriately: Exception handling and nested transactions[^] should help.


这篇关于如果提交t2然后t1回滚,如何解决SQL trasactions提交和回滚问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆