Ooops! Say you’ve performed an UPDATE statement without a WHERE condition against the database and overwritten a bunch of rows with bad data. How can you bring the right values back?
If you had a previously created backup that contains the original table values, you could easily recover the data. The most common solutions are:
- Restore the database backup and use it instead of the original database
- In case some other changes occurred after the UPDATE or you cannot allow the database to be offline:
- Restore a database backup on a test server
- Use SQL Server Management Studio Export data wizard to export the data
- Import the exported data into the original database
But, if you don’t have a full database backup, the UPDATEs can still be rolled back using the transaction information stored in the database online transaction log
The transaction log keeps the information about the transactions made to your database. If it hasn’t been shrunk or truncated, you can use ApexSQL Log or ApexSQL Recover
Both ApexSQL Log and ApexSQL Recover are tools that can mine the database transaction log files and rollback the accidental UPDATEs. So instead of having all the data in the table updated, you can roll back the UPDATE statement and then update only the data that fulfill a certain criteria
To recover data from accidental UPDATEs using ApexSQL Log or ApexSQL Recover:
-
Start the tool and connect to database
-
In the Select data sources step of the wizard choose to use online transaction log file and add applicable transaction log backup files or detached ldf files, depending on the use case.
-
Next, choose the Open results in grid option
-
In the Filter setup use the Time range section to narrow down the recovery to the time when the UPDATE statement was executed
-
In the Operations tab, check Update operation and ensure that all other DML and DDL operations are unchecked
-
Select the table(s) where the data was updated in the Filter setup options step, Tables filter
-
If possible, use the Users and Applications filters to narrow down the results
-
Click Finish
-
To create the Undo script:
-
Execute the script against the database
After the Undo script is executed, the UPDATEs are rolled back and the original data is back in the database before it was damaged
If you unintentionally UPDATE database records and you don’t have a full database backup, there is a chance to recover it using ApexSQL Log or ApexSQL Recover
April 4, 2013