Spotlight on ApexSQL Log : SQL Server Audit & Recovery Tool

The Row Detail pane

This pane shows the column level data for the particular operation. Listed are information about the field name, the data type, the length of the column and the value. In this pane you can also find tabs for “UNDO” and “REDO” scripts. These contain the reversing statement for the currently selected row in the main grid. From here the scripts can be copied into a query editor such as the SQL Server Management Studio and be executed. Note that only single row statements will be contained in these 2 tabs, no matter if the transaction spanned more than that one row. To reverse the effect of an operation which affected more than 1 row, you choose a different functionality from the context menu of the main grid, which I will come back to a little bit later on.

Up until now, you have an impression on the basic handling of the software. So, this is now the point from where we begin to explore what the software can do for you and how it can assist you in reversing the effects of mistakenly executed actions.

Case studies

For the following case studies I use a newly created database on SQL Server 2005 SP1. This database is set to “Full Recovery Mode” and contains 1 table named dbo.Nums. Here’s the DDL and the population script for that table:

 DROP TABLE dbo.Nums
SET @i = 1
WHILE @i <= 100000
 SET @i = @i + 1

Single row INSERT

Let’s start with a fairly simple, yet a somewhat constructed case. You wish to undo the following statement:

INSERT INTO dbo.Nums SELECT 100001
You probably ask yourself now, why we should bother with using a tool like ApexSQL Log to undo a simple INSERT statement. Well, you’re right. You don’t need the tool for this action, since you can simply issue an appropriate DELETE statement. However, this is just to get warm and show you that the software can handle such cases.

Once the INSERT statement has been fired, you can the corresponding entry in the main grid after you’ve refreshed the view:

From there you can move to the UNDO Script tab, copy the UNDO statement into a query editor and issue the DELETE statement, if you want to undo the modification immediately. Another option would be to create the UNDO script and run it during times of less(er) database activity.

Single row DELETE

Suppose we issue the following statement:

DELETE FROM dbo.Nums WHERE [Num] = 100001;
You basically apply the same steps I’ve described above to undo the single row INSERT.

Single row UPDATE

Again, typically the same procedure as above, but with the exception you should be aware of the fact that sometimes UPDATEs are done “in place ” and sometimes are not. When UPDATEs are, for some reason, not done in place, the operation consists of a DELETE followed by an INSERT. In such cases you will observe 2 entries in the log. To properly recover, you should make sure that you catch all affected rows from the log. This can easily and safely be done by using the “Select All Rows in this Transaction” function from the context menu of the main grid.

ApexSQL Log will automatically mark all rows affected by the transaction in the main grid.

Note that you need to take one more step, before you can create an undo script. You need to mark all these rows as checked before you can create that script. This functionality is also provided from the context menu of the main grid.

Now you can create your undo script and reverse the effect of the transaction.


Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |