views:

836

answers:

4

Is this like an "embedded" database of sorts? A file containing a built in database?

A: 

Yeah you're close. It's a Master Database File used to store some of the system information and sensitive data regarding the database.

A quick google search shows MSDN has a very descriptive page on it.

Hope this helps.

Jovan
This is not correct. The master database is not related to the MDF file extension.
Jon Galloway
How did this get an upvote? It's wrong
gbn
+6  A: 

SQL Server databases use two files - an MDF file, known as the primary database file, which contains the schema and data, and a LDF file, which contains the logs. See wikipedia. A database may also use secondary database file, which normally uses a .ndf extension.

As John S. indicates, these file extensions are purely convention - you can use whatever you want, although I can't think of a good reason to do that.

More info on MSDN here and in Beginning SQL Server 2005 Administation (Google Books) here.

Jon Galloway
A: 

This is a "master" database?

That doesn't make sense to me. If I open up a new project for an ASP.NET "webSite", and I add an App_data folder, and I add a database to this folder, the file that is created is a .mdf file. I can add any tables relevant to the application and query them. These tables don't have any system information. I'm sorry if I wasn't clear enough in my question.

When I add tables to this .mdf file, they're relevant to my application and I query this file instead of a SQL Server db.

It still is a SQL Server database. What you are doing here is relying on Visual Studio/ASP.NET functionality which is using SQL Express ( http://www.microsoft.com/express/sql/default.aspx ) to access the MDF. It is a standard SQL Server database file and you can even move that MDF file to a higher level SQL Server database server, attach it and rewite your data access code to use that database on a "server".
Joe Kuemerle
Thank you. That makes total sense. So it is really a SQL Express database then, so all Express limits apply including 4GB limit?
There is not a specific SQL Express database, it is a SQL Server database file. If you use SQL Server Express then you will be limited to 4 GB, if you move the file to SQL Server Standard (or higher) you will not be subject to that file size limitation
Joe Kuemerle
+3  A: 

Just to make this absolutely clear for all:

A .MDF file is “typically” a SQL Server data file however it is important to note that it does NOT have to be.

This is because .MDF is nothing more than a recommended/preferred notation but the extension itself does not actually dictate the file type.

To illustrate this, if someone wanted to create their primary data file with an extension of .gbn they could go ahead and do so without issue.

To qualify the preferred naming conventions:

  • .mdf - Primary database data file.
  • .ndf - Other database data files i.e. non Primary.
  • .ldf - Log data file.
John Sansom