恢复更新的数据 - SQL Server 2005

Nev*_*ess 1 sql sql-server sql-server-2005 database-update sql-update

我有一个问题,在使用sql server 2005时,我已执行更新查询而没有where子句(错误地)并且列的所有原始值都丢失了.

我怎样才能得到旧值?

欢迎提出任何建议/提示/解决方案,我们将不胜感激.

小智 6

嗨AngelIII,SQL服务器会保留每个转换的日志.因此,您可以从日志中恢复已修改的数据,而无需备份.

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') 
Run Code Online (Sandbox Code Playgroud)

这是artcile,它逐步解释,如何做到这一点.http://raresql.com/2012/02/01/how-to-recover-modified-records-from-sql-server-part-1/