我有一个问题,在使用sql server 2005时,我已经执行了更新查询而没有where子句(错误地)并且列的所有原始值都丢失了。
我怎样才能获得旧值?
欢迎任何建议/提示/解决方案,我们将非常感谢。
答案 0 :(得分:6)
嗨AngelIII, SQL Server会为每次转换保留日志。因此,您可以从日志中恢复已修改的数据,而无需备份。
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')
这是艺术,它逐步解释,如何做到这一点。 http://raresql.com/2012/02/01/how-to-recover-modified-records-from-sql-server-part-1/
答案 1 :(得分:1)
很难提供具体的解决方案,而不知道您采取了哪些预防措施。这些可能无法解决您的问题,但可能会阻止将来发生这种情况。
请不要使用SQL来改变生产数据,直到您已经回答了这个问题。