views:

24

answers:

2

Hello all,

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

+1  A: 

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;
Joe Stefanelli
I assure that the DB was detached cleanly. So you mean I will not lose any data? thank you
q0987
No, you may lose data depending on what was in the LDF - the transaction log.
Andrew Barber
@q0987: To guarantee no data loss, the SQL Server service would have to have been stopped.
Joe Stefanelli
Hello all, The target database has no transaction data and only contain static data
q0987
@q0987: In that case, you *should* be OK.
Joe Stefanelli
Quite interesting, if I directly attach the MDF file and igore LDF in my sql 2005 or 2008, I can load the db without problems. I don't know why people here uses a little complicated way. thank you
q0987
A: 

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

bobs