本文介绍了如果我从不提交,是否需要调用回滚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不使用自动提交连接到 SQL Server.如果一切都成功,我调用 commit.否则,我就退出.是否需要显式调用rollback,还是会在我们关闭连接而不提交时自动回滚?

I am connecting to a SQL Server using no autocommit. If everything is successful, I call commit. Otherwise, I just exit. Do I need to explicitly call rollback, or will it be rolled back automatically when we close the connection without committing?

以防万一,我正在 SAS 中的 proc sql 中执行 SQL 命令.

In case it matters, I'm executing the SQL commands from within proc sql in SAS.

更新:如果不调用回滚,SAS 可能会在 proc sql 块的末尾自动调用 commit.所以在这种情况下,回滚不仅仅是好的做法;很有必要.

UPDATE: It looks like SAS may call commit automatically at the end of the proc sql block if rollback is not called. So in this case, rollback would be more than good practice; it would be necessary.

最终更新:我们最终切换到了一个新系统,在我看来,它的行为与我们之前的系统相反.在未指定提交或回滚的情况下结束事务时,它将回滚.因此,下面给出的建议绝对是正确的:始终明确提交或回滚.

Final Update: We ended up switching to a new system, which seems to me to behave the opposite of our previous one. On ending the transaction without specifying committing or rolling back, it will roll back. So, the advice given below is definitely correct: always explicitly commit or rollback.

推荐答案

应该在连接关闭时回滚.强调应该是有原因的:-)

It should roll back on close of connection. Emphasis on should for a reason :-)

正确的事务和错误处理应该让您始终在满足提交条件时提交并在不满足时回滚.我认为在完成后始终提交或回滚并且不依赖断开连接/等是一个很好的习惯.只需一个错误或不正确/未关闭的会话即可为所有人创建阻塞链噩梦:-)

Proper transaction and error handling should have you always commit when the conditions for commit are met and rollback when they aren't. I think it is a great habit to always commit or rollback when done and not rely on disconnect/etc. All it takes is one mistake or incorrectly/not closed session to create a blocking chain nightmare for all :-)

这篇关于如果我从不提交,是否需要调用回滚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 10:47