Recover Updated Data - SQL Server 2005 [closed]

我只是一个虾纸丫 提交于 2019-12-08 03:18:42

问题


I have an issue that, while using sql server 2005 i have executed update query without where clause (by mistake) and all the original values of the column get lost.

How can I get old values??

Any suggestion/tips/solution is welcome and will be highly appreciated.


回答1:


Hi AngelIII, SQL server keeps log for every transation.So you can recover your modified data from the log as well without backup.

Select [PAGE ID],[Slot ID],[AllocUnitId],[Transaction ID] ,[RowLog Contents 0]
, [RowLog Contents 1],[RowLog Contents 3],[RowLog Contents 4] ,[Log Record]
FROM    sys.fn_dblog(NULL, NULL)   
WHERE AllocUnitId IN 
(Select [Allocation_unit_id] from sys.allocation_units allocunits 
INNER JOIN sys.partitions partitions ON (allocunits.type IN (1, 3)   
AND partitions.hobt_id = allocunits.container_id) 
OR (allocunits.type = 2 AND partitions.partition_id = allocunits.container_id)   
Where object_id=object_ID('' + 'dbo.student' + '')) 
AND Operation in ('LOP_MODIFY_ROW','LOP_MODIFY_COLUMNS')  
And [Context] IN   ('LCX_HEAP','LCX_CLUSTERED') 

Here is the artcile, that explains step by step, how to do it. http://raresql.com/2012/02/01/how-to-recover-modified-records-from-sql-server-part-1/




回答2:


  1. Restore a backup taken before the update
  2. Restore transaction logs to a point in time before the update
  3. Restore a copy of the table you made before the update
  4. Rollback the transaction that contains the update

It's difficult to offer a specific solution not knowing what precautions you have taken. These may not solve your problem, but may prevent this from happening in the future.

DON'T MESS AROUND WITH SQL THAT ALTERS PRODUCTION DATA UNTIL YOU HAVE ANSWERED THIS QUESTION.



来源:https://stackoverflow.com/questions/9053805/recover-updated-data-sql-server-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!