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:
- Go to [Start] [Run] and type CMD followed by [Enter]
- type cd [Enter] to go to the root C:
- type osql -E [Enter]
- 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?