SQL Server Master Database File (MDF/.mdf)

An MDF (Master Database File) file is the primary database file of Microsoft SQL Server with an extension .mdf, which contains the data as well as schema. We can create more than one data file with .mdf file extension for a database whether it does exist in a filegroup or by generating a new filegroup.

Database Files.

  • Microsoft SQL Server

Hex: 01 0F 00 00, ASCII

The default location of .mdf file depends on its SQL Server version.

SQL Server 2005

C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\

SQL Server 2008

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\

SQL Server 2008 R2

C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\

SQL Server 2012

C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\

SQL Server 2014

C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\

SQL Server 2016

C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\

  • Damaged file header
  • Improper system shutdown
  • Error 5171 – "Not a Primary Database File"
  • Error 5120 – "Access Denied While Attaching a Database"