What Is MDF and LDF in SQL Server

If you work with a SQL Server database, I'm sure you have heard of .mdf and .ldf files. When you install a new SQL Server database server on a machine, and create a database, these files are created on a hard drive. In this blog, let's learn about mdf and ldf files. 

MDF - Main Database File 

  • It contains all the main information of the database that is part of the server.
  • It plays a crucial role in information storage.

Note - All the successful queries go in MDF.

LDF - Log Database File

  • It stores information related to transaction logs for the main data file.
  • It stores changes related to CRUD Insert, Delete, and Update.

Note - All the unsuccessful or stuck queries go in LDF.

IMP Image Note

The below image shows the .mdf and .ldf files of EmployeeDB Database.

MDF vs LDF

Difference between MDF and LDF

MDF file is the primary file in SQL server database. The LDF is a supporting file.
MDF contains database record data.  Records information related to changes made in the server as well as all the actions performed.
MDF can vary in its file size with the change of the table and record data. 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.