或者你能得到一个隐式回滚

或者你能得到一个隐式回滚

本文介绍了DDL 语句是否总是给你一个隐式提交,或者你能得到一个隐式回滚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在事务进行到一半并执行 DDL 语句(例如截断表),则事务将提交.

If you're halfway through a transaction and perform a DDL statement, such as truncating a table, then the transaction commits.

我想知道这种情况是否总是如此,根据定义,还是隐藏在某处的设置可以回滚事务而不是提交.

I was wondering whether this was always the case and by definition, or is there a setting hidden somewhere that would rollback the transaction instead of committing.

谢谢.

编辑以澄清...

我不打算在截断后回滚.我只想确认已经执行的声明绝对总是将在 DDL 之前提交.只是想确保某处没有系统属性,有人可以设置来破坏我的代码.

I'm not looking to rollback after a truncate. I just want to confirm that statements already carried out are absolutely always going to be committed before a DDL. Just want to make sure there isn't a system property somewhere that someone could set to wreck my code.

我理解需要在 DDL 之前和之后提交,但从概念上讲,我认为可以通过在 DDL 之前回滚和之后提交来实现相同的一致性要求.

I understand the need to commit before and after a DDL, but conceptually I'd have thought the same consistency requirement could be achieved with a rollback before the DDL and a commit after.

推荐答案

不,它会一直提交.

如果要回滚,必须在 DDL 之前进行.

If you want to rollback, you'll have to do it before the DDL.

如果您想将 DDL 与现有事务隔离,那么您必须在它自己的独立事务中执行它.

If you want to isolate the DDL from your existing transaction, then you will have to execute it in its' own, separate transaction.

这篇关于DDL 语句是否总是给你一个隐式提交,或者你能得到一个隐式回滚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 06:48