Management Studio 2005:取消语句会触发回滚吗?
几分钟前,在制定新的存储过程时,我执行了错误的删除语句。就像这样:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,单个 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.
总是有交易。唯一改变的是这些事务如何相互隔离,并且在管理工作室中事务可能没有明确定义,并且在查询完成时自动提交。
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.