The SQL DBA’s worst nightmare is the loss of data due to their own mistake. It’s not uncommon for someone to improperly execute or even forget a WHERE clause entirely when executing DELETE or UPDATE queries, resulting in potentially millions of rows of compromised data
So, which SQL Server data recovery options are available?
The solution could be using a backup which was made right before the disaster.
Common solutions to recover lost database data using the existing database backup are:
- Restore the database backup and use it instead of the original database
- Restore the backup on the same server as the original database using a different database name
- Locate the relevant rows in the recovered database
- Update the broken rows using the original rows from the recovered database
Unfortunately, rarely is the recovery scenario so “neat and clean” as to allow for such a simple solution.
- Mistakes were not detected early enough
- There were subsequent data changes between the last database backup creation and the query execution which complicates the recovery significantly
- Influx of new data
- Database backups were not made regularly enough, or at all
Reading information from online transaction logs, transaction log backups or detached transaction logs, in order to recover database data, is one option to recover the data.
ApexSQL Log is a SQL Server recovery tool capable of reading transaction log data and recovering lost database data by rolling back transactions to their original state.
To recover lost database data due to accidental UPDATE or DELETE operations using ApexSQL Log:
- Start the tool and connect to the database
- In the select data sources step of the wizard, add the transaction log backups and detached transaction logs you want to read. Note that they have to form a full chain in order to provide successful auditing. Adding a database backup can help increase the performance and quality of audit trail data
- In the next step of the wizard, opt for the Open results in grid option
- Use the Filter setup options to narrow down the result set using the time, operation type, table’s name, user and other filtering options
- After you have set all options, click Finish
Your transactions will be listed in the application’s main grid. You can still use the Filter in the left pane to additionally eliminate unneeded transactions
To perform data recovery, check-in the transactions you want to roll back and click Undo in the Actions tab.
To execute the script from the script editor, click the Execute button or press F5 and the lost data will be restored into the database.
April 4, 2013