嵌套事务的目的 [英] Purpose of nested transactions
问题描述
我一直不明白嵌套事务有什么用.提交嵌套事务不会提交任何内容 - 它只会减少 @@TRANCOUNT
.ROLLBACK
回滚一切.
I have never understood what a nested transaction is good for. Committing a nested transaction commits nothing - it just decreases @@TRANCOUNT
. And ROLLBACK
rollbacks everything.
BEGIN TRANSACTION
//do an update
BEGIN TRANSACTION
//do an insert
COMMIT TRANSACTION
COMMIT TRANSACTION
这有什么区别:
BEGIN TRANSACTION
//do an update
//do an insert
COMMIT TRANSACTION
请举例说明为什么应该使用嵌套事务以及它们如何发挥作用.
Please give me an example why should nested transactions be used and how they make a difference.
推荐答案
嵌套事务允许您的代码调用其他代码(例如 SP),这些代码使用事务本身而无需在 实际提交事务他们提交.
Nested transactions allows your code to call other code (SPs for instance) which uses transactions itself without actually committing your transaction when they commit.
也就是说,您可以使用安全点在事务内回滚.
That said, you can use safepoints to roll back inside of a transaction.
有一篇 CodeProject 文章专门介绍
这篇关于嵌套事务的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!