Naveen's Weblog

Bridge to future

MDF and LDF Files

Posted by codingsense on December 30, 2008

MDF file and LDF file will be created automatically by MSSQL server when we create a new database in MSSQL. The files will be located at Installed Path -> MSSQL.1 -> MSSQL -> Data.
Whenever you create a Database ‘X’ in MSSQL, in the data folder 2 files will be created namely, X.mdf and X_log.ldf.

Difference between MDF and LDF file

MDF file is the Primary database file used by MSSQL in which user data will be present.

For each MDF file there will be a LDF file associated, this is the Transaction log file used by MSSQL to store the user transactions. This file will be used by MSSQL to recover the Primary Database file if it is corrupted.

Is there a need of LDF file?

Some of the users remove the LDF file since it grows very heavily after any transaction in MDF file. But it’s always suggested that to keep the LDF file with MDF file so that in recovery time the user will not repent. For the size problem you can use Shrink Database and Files to decrease the file size.

Happy Learning 🙂


Leave a Reply

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

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

Google photo

You are commenting using your Google 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

%d bloggers like this: