我有一个问题,在使用sql server 2005时,我在没有where子句的情况下执行了更新查询(错误地),并且该列的所有原始值都会丢失。
如何获取旧的价值观??
欢迎任何建议/提示/解决方案,我们将不胜感激。
你好,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')
这是一个技巧,它一步一步地解释如何做到这一点。http://raresql.com/2012/02/01/how-to-recover-modified-records-from-sql-server-part-1/
- 恢复更新前的备份
- 将事务日志恢复到更新前的某个时间点
- 恢复更新前制作的表的副本
- 回滚包含更新的事务
在不知道自己采取了哪些预防措施的情况下,很难提供具体的解决方案。这些可能不能解决你的问题,但可能会阻止这种情况在未来发生。
在回答这个问题之前,不要乱用SQL来更改生产数据。