Wednesday, June 6, 2012

Attach .mdf file to SQL server using SQL Server Management Studio

In this post i am going to explain, how to attach a *.MDF file to SQL Server 2005/2008
using SQL Server Management Studio.

In this post i will show how to attach a Northwnd database file.

First ADD the two files that is
1. northwnd database file and
2. northwnd log file (not necessary mostly)

and paste in the below location

C:\Program Files\Microsoft SQL Server\MSSQL10_50.MYDATABASE\MSSQL\DATA
Here MYDATABASE can be any thing like SQLExpress / the the name you gave at the installation time to your SQL Server.

In the below figure i didnt had a Northwnd database file in my sql server 2008 Express edition.

Right click on DATABASE and press attach as shown in the figure below

Now a window will open as shown in the below figure.
1. Press ADD and now you can see another window.
2. Select the database file in my case (Northwnd)
3. Press OK

 After that you can see as shown below figure.

Now Press OK at the bottom of the window and you will see the conformation window as shown below.

 Now i got an ERROR as shown below. (dont worry we can solve it.)

 Press OK and remove the Log file and press OK.

 Now you see the database was attached and we can see All the tables in the databse. 

No comments:

Post a Comment