How to attach existing database to sql server 2005

Hello Friends, today I will describe how I can attach a databse from its mdf and ldf file. For this we need to follow these steps:

  1. Copy the mdf file and ldf file of the database.
  2. Browse the Microsoft SQl Server Data folder: Open C:\ and then (Program Files) then (Microsoft SQL Server) then (MSSQL.1) then (Data)
  3. Verify the path in the address bar: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
  4. Now paste the mdf and ldf file of the database which you want to attach.
  5. Now open sql server management studio with administrator privilege .
  6. Connect with LocalHost server and right click on the database.
  7. Select Attach menu from right click options
  8. A dialog will be opened as shown in the picture below:how to attach a database to sql server 2005how to attach a database to sql server 2005


  9. Now click on add button  as shown in the above picture and select your mdf file and click ok.
  10. After adding the mdf file in the above dialog click on ok button as indicated in the picture.

These are the simple steps to attach a database from its mdf and ldf file.

Now you can carry these to files anywhere to restore your database to any machine. We can also restore database from its backup file. I will explain the steps in next post.

Happy coding. 🙂

3 thoughts on “How to attach existing database to sql server 2005

  1. “Under New York’s medical marijuana law, smoking and edible products will not be allowed. Instead, only marijuana pills, oils and vapors will be legal”–Huh. So I was wrong a few days ago saying that medical marijuana included smoking products–at least in New York. I think it’s different in other states, at least according to the sites I linked.

Leave a Reply to gihr Cancel reply

Your email address will not be published. Required fields are marked *