且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从表中检索已删除的记录

更新时间:2023-12-04 22:11:46

如果数据库处于完全恢复模式,则可以还原它时光倒流.否则,您需要还原备份以恢复该数据.

否则你也可以尝试这个

SQL Server为每个删除的记录保留日志.您可以通过"fn_dblog" sql服务器函数查询这些日志.
If your database is in full recovery mode then it is possible to restore it back in time. Otherwise you need to restore a backup to get that data back.

else u can try this also

SQL Server keeps log for each deleted records. you can query these logs via ''fn_dblog'' sql server function.
Select [RowLog Contents 0]
FROM   sys.fn_dblog(NULL, NULL)
WHERE  AllocUnitName = 'dbo.TableName'
       AND Context IN ( 'LCX_MARK_AS_GHOST', 'LCX_HEAP' )
       AND Operation in ( 'LOP_DELETE_ROWS' )


但是此日志为十六进制格式.并且您需要将此十六进制格式转换为您的实际数据.
请参阅以下内容: http://raresql.com/2011/10/22/how-to-recover-deleted-data-from-sql-sever/ [


But this log is in Hex format. and you need to convert this Hex format to your actual data.
refer this: http://raresql.com/2011/10/22/how-to-recover-deleted-data-from-sql-sever/[^]


没有办法.删除数据后,您将无法恢复数据,除非您具有外部恢复选项.

您只能使用交易 [回滚 [
There is no way to do this. Once you deleted the data, you''ll not be able to recover it, until and unless you have a external recovery option.

You can only prevent the data loss using Transactions[^]. Because a Rollback[^] option is there with it to rollback the data of previous stage.


     --Amit


不要从表中删除记录,只需添加一个新列即可保存是非.当您想要删除它时,只需将该记录的列值更新为false.之后,每当您要撤消已删除的操作时,都会触发另一个更新语句,以将记录的状态更改为true.并且每当您只希望不删除记录时,请在select语句中添加where子句以检查recordStatus以确定它是否被删除,或者使用true或false.
Don''t delete records from your table just add a new column which save true or false. When you want to delete it then just update that record''s column value to false. After that whenever you want to undo the deleted operation fire another update statement to change status of the record to true. And whenever you want only not deleted record add where clause in your select statement to check the recordStatus to determine it is deleted or not using true or false.