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 ![]()
