---
title: "What are .mdf and .ldf Files in SQL Database?"  
description: "What are .mdf and .ldf Files in SQL Database?"  
author: "Steilla Mitchel"  
published: 2023-08-30  
updated: 2023-08-30  
canonical: https://www.mindstick.com/forum/159794/what-are-mdf-and-ldf-files-in-sql-database  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# What are .mdf and .ldf Files in SQL Database?

What are **.mdf** and **.ldf [Files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud)** in [SQL Database](https://www.mindstick.com/articles/337535/connecting-to-sql-databases-ado-dot-net-essentials)**?**

## Replies

### Reply by Aryan Kumar

.mdf and .ldf files are [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) files used by Microsoft [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) Server.

- **MDF file (Primary Data File):** It stores all the data in a SQL Server database. This includes the tables, columns, rows, indexes, views, and stored procedures. The MDF file is typically the largest file in a SQL Server database.
- **LDF file (Log Database File):** It stores the transaction log for a SQL Server database. The transaction log is a record of all the changes that are made to the database. It is used to recover the database in case of a failure or to restore the database to a previous point in time. The LDF file is typically much smaller than the MDF file, but it can grow quickly if there is a lot of activity on the database.

Here is a table summarizing the key differences between .mdf and .ldf files:

| Feature | .mdf file | .ldf file |
| --- | --- | --- |
| Data stored | All data in the database | Transaction log |
| Size | Typically larger | Typically smaller |
| Purpose | Stores the data in the database | Stores the transaction log |
| Role in recovery | Not used for recovery | Used for recovery |


---

Original Source: https://www.mindstick.com/forum/159794/what-are-mdf-and-ldf-files-in-sql-database

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
