How to attach a database with missing log file

To attach a database to Sql Server 2008 without a log file, use this command:

EXEC sp_attach_single_file_db @dbname = 'dbname', @physname = 'c:SqlDatadbname.mdf'

 

This will work if there are no incomplete transactions in database.

In Sql Server 2005 log file would be automatically created when attaching database without one. Don’t know why this was changed.

Leave a Reply

Your email address will not be published. Required fields are marked *