Do I really need to keep .LDF files?
You shouldn't delete the log file. If you are trying to reattach a data file without the log, SQL Server can technically recreate it, but there are a few potential issues, like if there were open transactions when the database was detached. In which case, you'd have total data loss.
Consume the space, and don't delete your log files. You're asking for trouble with that.
See this article on Transaction Logs, in particular the "Log Mismanagement" portion.
As mentioned in another answer, you can't delete the log file. What you could do is set the database to READ_ONLY
. With the database in READ_ONLY
, no modifications are allowed and the log file will not grow. You could reduce the size of the log file to a minimal size and achieve your goal of a minimal footprint. To set the database in READ_ONLY
run the following command:
USE master;
GO
ALTER DATABASE databasename SET READ_ONLY;
GO
You can alter the database back to READ_WRITE
, make any changes needed, then set it to READ_ONLY
any time you need to.
The log file is still required to maintain the ACID properties of the database.
The fact is that you can create a database just using the mdf file. It's the sp_attach_single_file_db (Transact-SQL) command. Note that it will be removed in a future version of Microsoft SQL Server. But, it's not smart to delete your LDF files. Shark is right 'You're asking for trouble with that.' Another point of view - are your ldf files huge? If they are, you can do something about them.
- Set your database to Simple recovery model. You can do this only if you don't want to roll back the transactions
- Instead of making MDF and LDF files, create a full database backup (.BAK) file. It will be smaller tnan MDF+LDF