DBA Myths: Database file extentions


December 2, 2015 by Kenneth Fisher

Every now and again I hear or read that the only file extensions for a SQL Server database are mdf, ndf and ldf. Not true I’m afraid. And I truly wish it was. The file extensions can be whatever you want, or even nothing at all.

Note: Here are the common (recommended) usages.
mdf – Used for the primary data file.
ndf – Used for secondary data files.
ldf – Used for the log file(s).

Quick example for proof that you don’t actually have to use these file extensions.

CREATE DATABASE [BadFileExtentions]
( NAME = N'BadFileExtentions', 
	FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014CS\MSSQL\DATA\BadFileExtentions' , 
	SIZE = 5120KB , FILEGROWTH = 1024KB ),
( NAME = N'BadFileExtentions2', 
	FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014CS\MSSQL\DATA\BadFileExtentions.jpeg' , 
	SIZE = 5120KB , FILEGROWTH = 1024KB )
( NAME = N'BadFileExtentions_log', 
	FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014CS\MSSQL\DATA\BadFileExtentions.bak' , 
	SIZE = 1024KB , FILEGROWTH = 10%)

So what does this mean? Should we start naming our database files whatever we want? No, absolutely not! It means that you need to be extra careful when specifying the name of the files. You really don’t want to use non-standard file names. The confusion! The misunderstandings! Do you really want the operating system to think your database file is a really big picture? Or even worse (and while I realize this sounds like a stretch I’ve had it happen) you accidentally give your file a .bak extension. Then one day your automated process that deletes old bak files runs as the same time your instance is down. Bye bye database file.

10 thoughts on “DBA Myths: Database file extentions

  1. midnightdbasean says:

    When I had a team of DBAs I always put them through tons of training. One of the exercises I always put them through was to give them a server and tell them they have to delete these 3 files. And the first one to do it got some prize… either a couple days off, or a few books, etc. Anyway, the files were always SeanResume.docx, HRLoad.xlsx, MyPictures.pdf. This was during the windows lock portion of our training. I created a DB and made these the files and SQL had them locked. It always took them a while to figure it out. After several reboots, trying to rename, etc someone always finally investigated ways to see which files were locked and saw they were locked by SQL. Then after scratching their head for a couple more days decided that the only way SQL could be locking the files is if they belonged to a DB. So they checked and BAM, there it was.
    That sudden realization that SQL files done have to be what we see all the time. And like you showed above, they don’t even need extensions. Neither do backup files. They can be anything you like as well.
    Big Fun!

  2. midnightdbasean says:

    Also, one of the things I teach when I show people backups is that they can use the extension to help make sure nothing happens to it.
    backup database to disk = ‘C:\MyDB.ArchiveDONOTDELETE’
    Stuff like that.

  3. […] Kenneth Fisher on database file extensions: […]

  4. Caroline says:

    i just happened to be on that DBA team. Good times!!!

  5. Lars Jans says:

    Thanks , new for me. However in Oracle you can also make these mistakes or put a datafile in /var/tmp (linux)

  6. Michael says:

    Some good reasons not to deviate from the recommend extensions. Could avoiding an ant-virus program scanning them also be one?


    • It certainly can’t hurt. Most anti-virus programs can be told not to scan certain directories and I think can even be told to not scan certain extensions. So I’d say it’s easy enough to avoid them regardless.

  7. […] database is built of several components. There are two files, one for data and one for the log, the MDF and LDF files. Then there is the default filegroup PRIMARY. But that’s all just the […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 3,753 other subscribers

Follow me on Twitter

ToadWorld Pro of the Month November 2013
%d bloggers like this: