Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

How can I attach it?

share|improve this question

migrated from Sep 25 '12 at 9:03

This question came from our site for professional and enthusiast programmers.

Depends on whether it was cleanly shut down or not whether or not you can do so without problems. – Martin Smith Sep 25 '12 at 8:32
Have you tried something before asking? Making a quick search using almost same words as your first post is… – Yaroslav Sep 25 '12 at 8:35

E.g like this:

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

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

share|improve this answer
but I dont have a log file to remove.. – user1670625 Sep 25 '12 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.