如何回滚UPDATE语句? [英] How to roll back UPDATE statement?

查看:793
本文介绍了如何回滚UPDATE语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不恢复整个数据库的情况下进行?

Is this possible without restoring whole database?

我进行了一些我想撤消的更改,但是没有使DB脱机并进行了完全还原。

I have made changes which I would like to undo, but without putting DB offline, and doing full restore.

推荐答案

不,SQL Server没有Ctrl + Z。

No, SQL Server does not have Ctrl + Z.

通过将所有DML语句包装在事务中,可以保护自己免受这种情况的侵害。因此,您有以下查询窗口:

You protect yourself from this scenario by wrapping all DML statements in a transaction. So you have query windows with this:

BEGIN TRANSACTION;
UDPATE ...

-- COMMIT TRANSACTION;
-- ROLLBACK TRANSACTION;

运行更新时,请验证是否更新了正确的行数,正确的行,正确的方法,依此类推。然后根据您是否正确执行了更新,突出显示提交或回滚。

When you run the update, verify that you updated the right number of rows, the right rows, the right way, etc. And then highlight either the commit or the rollback, depending on whether you performed the update correctly.

在另一方面,请谨慎操作,因为否则,您可能会陷入混乱-开始交易,忘记提交或回滚,然后出去吃午餐,请假,去度假等等。

On the flip side, be careful with this, as it can mess you up the other way - begin a transaction, forget to commit or rollback, then go out for lunch, leave for the day, go on vacation, etc.

不幸的是,这只会帮助您前进。在当前情况下,最简单的方法是还原数据库的副本,并从该副本中收集数据(无需完全覆盖当前数据库即可还原)受此更新影响的数据。)

Unfortunately that will only help you going forward. In your current scenario, your easiest path is going to be to restore a copy of the database, and harvest the data from that copy (you don't need to completely over-write the current database to restore the data affected by this update).

这篇关于如何回滚UPDATE语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆