Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.67/5 (5 votes)
See more:
Can I recover deleted data from sql server 2008.
table is on server not in local.
Posted
Comments
Member 13005879 12-Dec-20 7:09am    
I have restored the DB by using 2 days old .bak file, Is there any option to recover the yesterday data..?
Please suggest me if any one knows..

Server keeps log for each deleted records.You can query these logs via 'fn_dblog' sql server function with the table name and it will give you all the deleted records from the log.
SQL
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' )

But this log is in Hex format. and you need to convert this Hex format to your actual data.
Given below is the article will help you to recover the deleted records in the same way defined above.

How to recover deleted data from SQL Server[^]
 
Share this answer
 
v2
Comments
jaideepsinh 8-Aug-13 8:42am    
This one work but not for all time? what's the reason?
HardikPatel.SE 17-May-14 9:30am    
This link will be Helpful for you : http://www.mssqltips.com/sqlservertip/3160/recover-deleted-sql-server-data-and-tables-with-the-help-of-transaction-log-and-lsns/
the content is from the link...
http://thehobt.blogspot.com/2008/12/recovering-deleted-data-in-sql-server.html[^]

Backup and restore the transaction log using the STOPAT clause

If your database is set to use the Full Recovery Model, you may have a backup and restore option, even if you didn’t take a backup prior to the data modification. In order to do this:

1.Backup the tail of the transaction log using normal BACKUP LOG syntax, and specifying WITH NORECOVERY. For further detail see Tail-Log Backups on MSDN.
2.Restore your most recent full backup, making sure to specify NORECOVERY.
3.Restore the most recent differential backup, also specifying NORECOVERY.
4.Restore each transaction log backup taken since the last full or differential backup. For the final log backup, use the STOPAT clause to stop the restore immediately prior to the data modification. Before you access the database, you need to perform recovery, so you can either do it as part of this restore, or as a separate operation. For more information, have a look at Recovering to a Specific Point in Time on MSDN.

This will, of course, wipe out any activity which took place after the time/LSN/mark specified in the STOPAT clause.


Use a log explorer, or similar recovery tool to generate undo scripts

A number of vendors offer tools which allow you to explore the transaction log and generate undo scripts to roll back data modifications. I have had occasion to use any of these utilities myself, however the most commonly recommended utilities are RedGate’s SQL Log Rescue and ApexSQL’s ApexSQL Log. These aren’t plugs – as I said, I haven’t used either of them, so please don’t complain if you do and they don’t work out for you.
 
Share this answer
 
Comments
c27bharti 17-Nov-11 7:44am    
thank u for reply
If you don't have any backup of your database, AFAIK you cannot recover the deleted data.
 
Share this answer
 
Comments
CHill60 7-Jan-14 10:53am    
Other than via the methods detailed in Solutions 1 and 2 from 2 years ago :-)
Sandeep Mewara 7-Jan-14 11:52am    
:( All I can say, when I visited this thread there was no answer. You can try this link: http://www.codeproject.com/Answers/599155/canplusiplusrecoverplusdeletedplusdataplusfromplus#answer3 which I came across from forum today.

CHill60 7-Jan-14 12:10pm    
I've noticed that quite a few times recently too - thought it was just my slow connection. If I spot it again I'll post it on the site bugs as now I know I'm not the only one :-)
More than likely not. The space is going to get reused and the deleted data will be overwritten.

The best way to avoid this situation is regular backups of the data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900