0

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

How can I attach it?

2
  • 1
    Depends on whether it was cleanly shut down or not whether or not you can do so without problems. Commented 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
    Commented Sep 25, 2012 at 8:35

3 Answers 3

8

E.g like this:

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

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

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

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 you have read our privacy policy.