如何在 SQL Server 2005 中回滚 UPDATE 查询?
如何在 SQL Server 2005 中回滚 UPDATE 查询?
我需要用 SQL 来完成此操作,而不是通过代码。
How can I rollback an UPDATE query in SQL server 2005?
I need to do this in SQL, not through code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果您已经执行了查询并想要将其回滚,不幸的是,您唯一真正的选择是恢复数据库备份。 如果您使用完整备份,那么您应该能够将数据库恢复到特定时间点。
If you've already executed the query and want to roll it back, unfortunately your only real option is to restore a database backup. If you're using Full backups, then you should be able to restore the database to a specific point in time.
你需要这个工具,你可以找到交易并将其逆转。
ApexSQL 日志
You need this tool and you can find the transaction and reverse it.
ApexSQL Log
您可以为此使用隐式事务
根据您的要求 - 您可以通过将存储过程设置为启动过程来从存储过程设置此设置 (
SET IMPLICIT_TRANSACTIONS ON
) 。但是 SET IMPLICIT TRANSACTION ON 命令是特定于连接的。 因此,除了运行启动存储过程的连接之外的任何连接都不会从您设置的设置中受益。
You can use implicit transactions for this
As you request-- You can SET this setting (
SET IMPLICIT_TRANSACTIONS ON
) from a stored procedure by setting that stored procedure as the start up procedure.But
SET IMPLICIT TRANSACTION ON
command is connection specific. So any connection other than the one which running the start up stored procedure will not benefit from the setting you set.您可以回滚在事务中执行的语句。
不提交事务,而是回滚事务。
如果您更新了某些内容并想要回滚这些更新,并且您尚未在(尚未提交的)事务中执行此操作,那么我认为这只是运气......
(手动修复或恢复备份)
You can rollback the statements you've executed within a transaction.
Instead of commiting the transaction, rollback the transaction.
If you have updated something and want to rollback those updates, and you haven't done this inside a (not-yet-commited) transaction, then I think it's though luck ...
(Manually repair, or, restore backups)
一旦提交更新,您就无法仅回滚单个更新。 最好的办法是回滚到以前的数据库备份。
Once an update is committed you can't rollback just the single update. Your best bet is to roll back to a previous backup of the database.
根据您指定的信息,恢复的最佳机会是通过数据库备份。 我认为您将无法回滚您所推动的任何更改,因为您当时显然没有使用事务。
From the information you have specified, your best chance of recovery is through a database backup. I don't think you're going to be able to rollback any of those changes you pushed through since you were apparently not using transactions at the time.
简单易行:
标题代码...
工作代码...
代码...
“从 Excel 复制数据”
错误:
...
Simple to do:
header code...
Working code...
code....
'Copy Data FROM Excel'
ERRORHAND:
...
如前所述,除了从备份恢复之外,您无能为力。 至少现在您将学会始终将语句包装在事务中,以便在决定提交之前查看会发生什么。 另外,如果您没有数据库备份,这也会教您定期备份数据库。
虽然我们对您当前的问题没有提供太多帮助...但愿这些答案将确保您将来不会再次遇到此问题。
As already stated there is nothing you can do except restore from a backup. At least now you will have learned to always wrap statements in a transaction to see what happens before you decide to commit. Also, if you don't have a backup of your database this will also teach you to make regular backups of your database.
While we haven't been much help for your imediate problem...hopefully these answers will ensure you don't run into this problem again in the future.
在此示例中,我们运行 2 行插入查询,如果所有这些都为 true,则运行,但如果不是,则不运行任何内容并回滚
in this example we run 2 line insert into query and if all of them true it run but if not no run anything and ROLLBACK
尝试
一下通常会有效
Try
It usually works