I want to attach a database to SQL Server 2005 but I have only its .mdf file

How can I attach it?

  • 1
    Depends on whether it was cleanly shut down or not whether or not you can do so without problems. Sep 25, 2012 at 8:32
  • 2
    Have you tried something before asking? Making a quick search using almost same words as your first post is blog.sqlauthority.com/2010/04/26/…
    – Yaroslav
    Sep 25, 2012 at 8:35

3 Answers 3


E.g like this:

CREATE DATABASE AdventureWorks2012 ON (FILENAME = '{drive}:\{file path}\AdventureWorks2012_Data.mdf') FOR ATTACH_REBUILD_LOG;

Simply,When you attach database, it will display Attach Database dialog box in which click the logfile location and click the remove button. When you click OK, a logfile for you database will be created....

enter image description here

  • but I dont have a log file to remove..
    – user1670625
    Sep 25, 2012 at 8:54

When you attach the mdf via the UI, select the ldf file in the list of files and remove it. A new one will be created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.