Question

I have a backup database file (i.e. test.mdf), however, I don't have the LDF file. I was told that SQL Server 2008 R2 can load MDF without LDF.

Is that true?

Thank you

Was it helpful?

Solution

Assuming the database was detached cleanly, you should be able to use sp_attach_single_file_db or the newer CREATE DATABASE...FOR ATTACH syntax.

EXEC sp_attach_single_file_db 
    @dbname = 'YourDB', 
    @physname = N'C:\YourFile.mdf';

OR

CREATE DATABASE YourDB
      ON (FILENAME = 'c:\YourFile.mdf') 
      FOR ATTACH_REBUILD_LOG;

OTHER TIPS

Another option to sp_attach_single_file_db is the CREATE DATABASE command with the FOR ATTACH_REBUILD_LOG option.

This has worked for me. I used EMERGENCY mode to see database:

http://forums.asp.net/t/1903548.aspx

You have two options:

  1. You can create an empty database with the same name and physical file layout, shut down the server, swap in the files you want to attach in place of the empty DB files, and start the server. The database should come up in suspect mode. You can then ALTER DATABASE SET EMERGENCY to put it in emergency mode, and then run DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS. This will pull as much data as possible out of the log to make the database consistent, but may have to delete some data in order to make the database consistent. This is the option which is most likely to get the maximum data back.
  2. You can attempt to use the CREATE DATABASE FOR ATTACH_REBUILD_LOG to see if that will bring it back. If the database was cleanly shut down, you MIGHT be able to succeed. There is also the chance that the database will be inconsistent or corrupt if there are transactions which could not be rolled back. You should in any event run DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS to make your database consistent. In this event, SQL Server will make no attempt to mine information from the log. It will ignore the contents of the log. If there were transactions in process no rollback will be possible, so the ALLOW_DATA_LOSS will be required.

For more please try to refer to:

http://blog.sqlauthority.com/2008/07/21/sql-server-fix-error-9004-an-error-occurred-while-processing-the-log-for-database-if-possible-restore-from-backup-if-a-backup-is-not-available-it-might-be-necessary-to-rebuild-the-log/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top