Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
1  
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
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 '12 at 8:35
add comment

migrated from stackoverflow.com Sep 25 '12 at 9:03

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

3 Answers

E.g like this:

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

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
add comment

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
add comment

Your Answer

 
discard

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