Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need the LDF files along with MDF files?

Tags:

sql-server

mdf

What would happen if I delete the .ldf file that is in the same folder that my .mdf file?

like image 378
Oscar Mederos Avatar asked May 10 '11 06:05

Oscar Mederos


People also ask

What is the use of LDF file in SQL Server?

The LDF file is the transaction log that allows you to perform “point in time” restores if you have system failures. The way it works is that you can restore from your last full backup and “replay” the transactions from the transaction log file.

Do you need the LDF file?

The LDF file is the transaction log and is required for all SQL server configurations. Depending on the recovery mode, will determine how it is used. However all queries basically get stored here until successfully committed to the database (MDF). You will not be able to delete it while SQL server service is running.

Can we restore database without LDF file?

Attach MDF File Without LDF file by using T-SQL script: You can also run a TSQL Script on SQL Query to restore MDF database in SQL Server and recreate your transaction log file. Where, testdb is the name of your database. Now you can check your database in the database folder.


1 Answers

The LDF file is the transaction log and is required for all SQL server configurations. Depending on the recovery mode, will determine how it is used. However all queries basically get stored here until successfully committed to the database (MDF).

You will not be able to delete it while SQL server service is running. You can detach the database, delete the log file (LDF) and reattach the data file (MDF). However it will just create a new log file. You really should not need to delete it. If it is getting too large you will need to manage it, typically through the backup process.

like image 91
Dustin Laine Avatar answered Nov 11 '22 09:11

Dustin Laine