Management Studio 2005:取消语句会触发回滚吗?

发布于 2024-08-05 00:05:30 字数 286 浏览 5 评论 0原文

几分钟前,在制定新的存储过程时,我执行了错误的删除语句。就像这样:

Delete From SomeTable Where SomeStatusID=1

10 秒后,我意识到我输入了错误的状态并点击了取消。据称该声明已被取消。

我对一个单独的数据库进行了恢复,以取回我可能刚刚删除的表,认为由于这不在事务中,因此某些记录可能已被删除。

奇怪的是,这些记录都完好无损。只是好奇为什么会这样——在这种情况下,即使没有定义显式事务,它是否将单个删除语句视为事务?

A few minutes ago, while working out a new sproc, I executed the wrong delete statement. Something like this:

Delete From SomeTable Where SomeStatusID=1

10 seconds into it, I realized that I typed in the wrong status and hit cancel. It said that the statement was canceled.

I did a restore to a separate database to get back the table that I just presumably nuked, thinking that since this was not in a transaction some records were probably deleted.

Oddly, the records were all intact. Just curious as to why this was -- did it treat the individual delete statement as a transaction in this case, even though there was not an explicit transaction defined?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情癖 2024-08-12 00:05:30

默认情况下,单个 DML 语句作为事务执行。如果该语句成功,则提交事务。如果该语句被取消或以其他方式失败,则事务将回滚。

此行为内置于引擎中,与 Management Studio 无关。请参阅文档中的自动提交事务

By default, a single DML statement is executed as a transaction. If the statement succeeds, the transaction is committed. If the statement is cancelled or otherwise fails, the transaction is rolled back.

This behavior is built in to the engine, and is not related to management studio. See Autocommit Transactions in the docs.

深巷少女 2024-08-12 00:05:30

总是有交易。唯一改变的是这些事务如何相互隔离,并且在管理工作室中事务可能没有明确定义,并且在查询完成时自动提交。

There are always transactions. The only thing that changes is how those transactions are isolated from each other and that in management studio the transaction might not be defined explicitly and is auto-committed when the query finishes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文