This sections aims to explain in brief the functions of MDF and LDF files in an SQL server database. Other than that, the post also explains basic differences between the two.
MDF and LDF Files in SQL Server Database

Most of the companies use MS SQL Server for storing and managing information. That makes Microsoft SQL Server one of the most used programs globally. Within each database, you will find two files namely; MDF and LDF. The two happens to be very crucial in ensuring uninterrupted functioning of the database.
Role in Backing up and Restoring Database

Information Contained in MDF and LDF files
MDF – It stands for Master Database File. It contains all the main information of the database that are part of the server. This extension also points to various other files. It plays a crucial role in information storage. Overall it is very important for safe and secure supervision of data. In case this file gets damaged, an MDF recovery procedure is conducted to recover it. Doing so is important in order to save the data from going missing.
LDF – This file stores information related to transaction logs for main data file. It basically keeps track of what all changes have been made in the database. The information that this file stores ranges from date/time of change, details of the changes made, as well as information related to whoever made the changes. Information related to computer terminals where changes took place is also stored in the logs.
LDF stores changes related to inserts, deletion, updates, addition, etc. Transaction logs kept in the server help in identifying activities related to unauthorized changes as well as where an error is originating. Log information can sometimes come handy in fixing errors, recovering important data, and identifying anomalies.
SQL Operations where LDF Files Play an Important Role
Primarily LDF files are important in three major SQL operations:
- Recovering incomplete transactions when server is started.
- Recovering individual transactions.
- Recovering database in times of failures.
Comparison between MDF and LDF Files
- MDF file is the primary file in SQL server database. The LDF is a supporting file. The latter stores the information related to transaction logs.
- MDF contains database record data. LDF, on the other hand records information related to changes made in the server as well as all the actions performed.
- Unlike MDF, LDF is primarily about three major operations that were mentioned earlier.
- LDF files can go on to consume a lot of storage space depending on the number of changes made in the server as well as the number of transactions that took place. MDF, on the other hand can vary in its file size with the change of the table and record data.
Author Introduction:
Peter Song is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including outlook recovery and PDF recovery software products. For more information, visit www.datanumen.com.