Why to Read SQL Server Transaction Log?
Before revealing to you why we need to read the transaction logs on SQL Server, it is necessary for you to know what kind of data is caught by the transaction logs.Basic Operation:The transaction log captures all the fundamental DML Operations like INSERT, UPDATE, DELETE and furthermore captures DDL Operations like CREATE, TRUNCATE, and DROP
Presently, getting to the heart of the matter, reading SQL Server transaction logs is important because the transaction logs contain all the information about the transactions which we have performed on our database. Moreover, this information can be used in forensics:
- To find those records which have been erased erroneously or;
- If the size of our log file is growing automatically or;
- Lost information need to be recuperated
The fn_dblog() function (formerly known as the DBCC command) is one of several undocumented functions for SQL Server; it allows you to view the transaction log records in the active part of the transaction log file for the current database.
Note that use of the fn_dblog() function (and all other undocumented commands) against a production database instance is executed at your own risk.
fn_dblog() Parameters
The fn_dblog() function accepts two parameters:
- The first is starting log sequence number, or LSN. You can also specify NULL, which means it will return everything from the start of the log.
- The second is the ending LSN. You can also specify NULL, which means you want to return everything to the end of the log.
fn_dblog() Example:
This basic fn_dblog() function statement will return details from the transaction log:
SELECT * FROM fn_dblog(NULL, NULL)