top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Explain the Steps to Attach & Detach Database?

+2 votes
221 views
Explain the Steps to Attach & Detach Database?
posted Feb 2, 2016 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

Steps to Attach & Detach Database.
How to Attach & Detach .mdf and .ldf files:

Follow the steps mentioned below:

Open Sqlserver Management Studio and select the database from the databases tree view and right click on the selected database which you want to Detach.
Select All tasks > Detach Database from the drop down menu options

enter image description here

Following Dialog box will appear.

enter image description here

Now click on OK .The database successfully is detached, Once the database is detached, that database name will not be shown under databases tree view
Note: Attach &Detach Operations can be done when the Database is not in use.when it is in usage then it will not allow to proceed and the following error message will appear

Now copy the .mdf and .ldf files of the database from the location (example: C:\Program Files\Microsoft SQL Server\MSSQL\Data) as shown in the following diagram
Paste the copied files (mdf & ldf) into the new location or new disk.
Right click on Databases and select option All Tasks > Attach Database from Drop down

enter image description here

The following dialog box will appear prompting for MDF file location

enter image description here

Click on add and select mdf and ldf files which were stored.

enter image description here

answer Feb 2, 2016 by Manikandan J
...