This topic describes how to detach a database.
Detaching a database removes it from the instance of SQL Server but leaves the database intact within its data files and transaction log files. You can later use these files to attach or move the database to any instance of SQL Server, including the server from which the database was detached.
Before detaching a database, ensure:
1. Connect to a server instance.
2. In Database Explorer, right-click the database you want to detach and select Tasks > Detach Database.
3. In the Detach Database dialog, select the checkboxes next to the following options:
Note
You cannot detach a database with active connections.
Note
By default, the detach operation retains any outdated optimization statistics.
4. To save the changes, click OK.
The database gets the icon, indicating that the database was detached.
5. To close the dialog, click Close.
1. In Database Explorer, hold down Ctrl and select the required databases.
2. On the shortcut menu, select Tasks > Detach Database.
3. In the Detach Database dialog, select the checkboxes next to the required options, then click OK.
4. To close the dialog, click Close.
If the database fails to detach, hover over the error message in the Status column to view details. The message also provides guidance on resolving the issue and completing the detach operation.