问题描述
Hi,
我有一个不同的要求,我需要遵循.请在下面的查询中建议如何完全回退数据库A和数据库B的两个不同事务.
I have a different requirement that i need to follow. Please suggest on the below query as how to rollback completely with two different transactions for database A and database B.
开始交易1
将Batch1插入数据库A
Insert Batch1 in database A
提交
结束交易1
如果出现错误
If Error
nbsp; bsp 数据库A中的日志错误.
Log Error in database A.
nbsp; bsp Transaction1.回滚
Transaction1.Rollback
nbsp; bsp 退出
Exit
其他
Else
nbsp; bsp 开始交易2
Begin Transaction2
nbsp; bsp 从(在数据库A中插入Batch1)中获取密钥
Take key from (Insert Batch1 in database A)
nbsp; bsp 将Batch1插入数据库B.
Insert Batch1 into database B.
提交
commit
nbsp; bsp 结束交易2
End Transaction2
nbsp; bsp 如果出现错误
If Error
nbsp; bsp nbsp; bsp 数据库中的日志错误.
Log Error in DB.
Transaction2.回滚
Transaction2.Rollback
nbsp; bsp 结束
End
结束
End
请让我知道上面的伪代码是否正确 或向我提供正确的代码.
Please let me know whether above psuedo code is correct or provide me the correct one.
谢谢,
萨姆帕特
Sampath
推荐答案
从概念上讲,您必须将第二个事务嵌套在第一个事务中.当然,这个建议与技术无关,就像您的问题一样.
Conceptually, you have to nest the second transaction within the first. Of course this advice is technology agnostic, as is your question.
这是我要如何获取您的伪代码:
Here is how I would have your pseudo code:
Begin Transaction1 Insert Batch1 in database A commit If Error Log Error in database A. Transaction1.Rollback Exit End If
开始交易2从(从数据库A中插入Batch1)获取密钥将Batch1插入数据库B.犯罪如果出错数据库中的日志错误.Transaction2.回滚交易1.回滚出口如果结束
Begin Transaction2Take key from (Insert Batch1 in database A)Insert Batch1 into database B.commitIf ErrorLog Error in DB.Transaction2.RollbackTransaction1.RollbackExitEnd If
结束交易2结束交易1
End Transaction2End Transaction1
这篇关于处理多个事务并完全回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!