MDF File
SQL Server Database File (.mdf)
What is a MDF file?
An MDF file is a Microsoft SQL Server database data file. It’s typically the primary data file for a database and contains tables, indexes, stored procedures, and other database objects and data pages.
Common uses
- Storing SQL Server database data (primary data file)
- Attaching/restoring databases in SQL Server
- Moving databases between servers (with LDF/other files)
- Development and testing database snapshots
- Database recovery and forensics (advanced use)
How to open a MDF file
- Windows: SQL Server Management Studio (SSMS) + SQL Server to attach/open
- Developers: Use LocalDB/SQL Server Express for local testing
- Tip: MDF usually pairs with an .ldf log file—keep them together when possible
Common problems
- Can’t attach because SQL Server version is older/newer
- Missing or mismatched LDF (transaction log) file
- Permissions: SQL Server service account can’t access the file path
- Corruption after crash or incomplete copy
- Database already in use/locked when attaching
History
MDF has long been used as SQL Server’s main database data file format. Over time, SQL Server added features like multiple data files (NDF), improved recovery, and compatibility levels, but MDF remains the core container for database pages and objects.