How to attach/detach a database without Enterprise Manager?

Introduction:

Due to various reasons it can be possible that the Enterprise Manager cannot be used to attach/detach a database in SQL. For example when the MSDE version of SQL is used, the Enterprise Manager is not available. In this case MS-Dos can be used to attach/detach the database.

Explanation:

In order to attach/detach a database via MS-Dos follow the steps below:

  1. Go to [Start] [Run] and type CMD followed by [Enter]
  2. type cd [Enter] to go to the root C:
  3. type osql -E [Enter]
  4. now, 1> will appear. The commandline can now be entered.
Attach a database:
  • In the commandline type sp_attach_db ‘databasename’,’C:path to databasesdatabase.mdf’,’C:path to databasesdatabase.ldf’ [Enter]
  • In the second line type go [Enter]
  • Now if no message appears the database has been attached succesfully!

Detach a database:
  • In the commandline type sp_detach_db ‘databasename’
  • In the second line type go [Enter]
  • Now if no message appears the database has been detached succesfully!

 

Source: How to attach/detach a database without Enterprise Manager?

Leave a Reply

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