Category: Uncategorized

How to read Transaction Log File

Today morning, one of my colleague came to my desk with an interesting question. “Is there any way to read SQL T-Log file?” I did not have idea about it I searched on google and I found an un-documented functions which is used to read T-Log file. Using this function, we can get list of all transaction performed on database. Function name is fn_dblog() (Formally known as DBCC command).

The fn_dblog() will accept two parameters:

  1. Starting log sequence number (LSN). We can specify null, it will return everything from start of log.
  2. Ending log sequence number (LSN). We can specify null, it will return everything to end of the log.

Demo Code:

I have created new database named “SampleDatabase”. Then I created new table called “Inventory” and insert some values in table.
Now I want to get all the transaction (Insert, Update, Delete, create Table) performed by on database. So, I can run below query.

In above code, you can see I used the fn_dblog function in the “FROM” clause. I also used the ��WHERE” predicate to return only transaction log rows that involved a CREATE TABLE, INSERT and/or DELETE transaction created by database user Nisarg-PC\Nisarg.

This function is undocumented and you should use it with caution.

SQL Server: Choosing best high availability technique

As a DBA sometimes we came across the situation when we have to choose a best High Availability and Disaster recovery solutions.

Each has its own advantages and limitations.

To provide an accurate choice which technology to use, DBAs must have through understanding of business needs for high availability, How fast  should fail-over happen,how many replicas  required and if reads can happen on the secondary. Each SQL Server High availability technology has  short comings on a different dimensions.

Here is a quick table for reference.

Feature  Fail over clustering Database Mirroring  Log Shipping Transactional Replication
Storage redundancy ?  No Yes Yes Yes
 No need for special hardware? No Yes Yes Yes
Role change automatically Yes Yes No No
No need for additional server ? None Witness Monitor* Distributor*
Reports read from secondary ? NA No Read only Yes
Scope of availability Instance level Complete Database Complete Database Database Objects
 Multiple secondary client NA No Yes Yes
Auto redirection after failover Yes No: Need custom solution No: Need custom solution No: Need custom solution
Recovery Model Any Full Full Any