从无意中更新的数据库回滚数据 [英] Rollback data from database which was updated unintentionally

查看:106
本文介绍了从无意中更新的数据库回滚数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中的数据无意中更新了...我想从数据库中回滚以前的数据...有没有办法恢复我以前的数据..Plz any1帮助我..

解决方案

如果没有维护事务日志,则无法回滚。



如果您有日志,请参阅:使用事务日志回滚数据 [ ^ ]



此外,如果你有备份然后从那里恢复它。

另一个类似的讨论与可能的答案,阅读:类似的讨论 [ ^ ]


仅当数据库处于完全恢复模式时才可以这样做。您没有指定您的SQL Server版本。如果你在2000年,你可以使用这个免费的工具 [ ^ ],否则使用此< a href =http://www.apexsql.com/sql_tools_log.aspx>工具 [ ^ ]。另请查看以下文章:



如何在SQL Server 2005中回滚UPDATE查询? [ ^ ]

< a href =http://stackoverflow.com/questions/9767054/read-the-log-file-ldf-in-sql-server-2008>读取sql server 2008中的日志文件(* .LDF) [ ^ ]


尝试以这种方式找出



 BEGIN TRY  - 启动Try Block .. 
BEGIN TRANSACTION - 开始交易..

UPDATE MyCurrentAccount SET Amount = Amount - 1000
WHERE AccountId = 004

更新MySavings S. ET Amount = Amount +'sssdgsggs'
WHERE AccountId = 004

COMMIT TRAN - 交易成功!
END TRY
BEGIN CATCH
IF @@ TRANCOUNT> 0
ROLLBACK TRAN - 出现错误时出现错误
END CATCH


创建表MyCurrentAccount(AccountId int,Amount int)
创建表MySavings( AccountId int,Amount int)

select * from MyCurrentAccount

select * from MySavings

insert into MySavings values(004,50000)


Tht data in my database was updated unintentionally...i want to rollback ma previous data from database...Is there any way to recover my previous data..Plz any1 help me ..

解决方案

If there is no transaction logs maintained then it cannot be rolled-back.

If you have logs, see: Rollback data with transaction log[^]

Further, in case if you had backup then just restore it from there.
Another similar discussion with possible answers, read: Similar discussion[^]


This is only possible if your database was in full recovery mode. You didnt specified your version of SQL server. If you are on 2000 than you can use this free tool[^] from Red Gate, otherwise use this tool[^] from ApexSQL. Also check out the following articles:

How can I rollback an UPDATE query in SQL server 2005?[^]
Read the log file (*.LDF) in sql server 2008[^]


try to find out in this way

BEGIN TRY --Start the Try Block..
    BEGIN TRANSACTION -- Start the transaction..

        UPDATE MyCurrentAccount SET Amount = Amount - 1000
            WHERE AccountId = 004
 
        UPDATE MySavings SET Amount = Amount + 'sssdgsggs'
            WHERE AccountId = 004
 
    COMMIT TRAN -- Transaction Success!
END TRY
BEGIN CATCH
    IF @@TRANCOUNT > 0
        ROLLBACK TRAN --RollBack in case of Error
END CATCH


Create table   MyCurrentAccount(AccountId  int,Amount int) 
Create table  MySavings (AccountId  int,Amount int) 

select * from MyCurrentAccount

select * from MySavings

insert into MySavings values(004,50000)


这篇关于从无意中更新的数据库回滚数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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