Menu ▼



Posted By :
avatarLearn DotNet
Total Views : 960

Steps to Attach & Detach Database

                            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


  • Following Dialog box will appear.


 
  • 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


  • The following dialog box will appear prompting for MDF file location


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


  • Select the Data based and On Clicking ‘OK’, the data base will be attached  







comments powered by Disqus


Search dotnetlearners.com