Detach a Database
This topic describes how to detach a database in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL. The detached files remain and can be reattached by using CREATE DATABASE with the FOR ATTACH or FOR ATTACH_REBUILD_LOG option. The files can be moved to another server and attached there.
In This Topic
-
Before you begin:
-
To detach a database, using:
Limitations and Restrictions
For a list of limitations and restrictions, see Database Detach and Attach (SQL Server).
Security
To detach a database
-
In SQL Server Management Studio Object Explorer, connect to the instance of the SQL Server Database Engine and then expand the instance.
-
Expand Databases, and select the name of the user database you want to detach.
-
Right-click the database name, point to Tasks, and then click Detach. The Detach Database dialog box appears.
-
When you are ready to detach the database, click OK.
Note
|
|---|
|
The newly detached database will remain visible in the Databases node of Object Explorer until the view is refreshed. You can refresh the view at any time: Click in the Object Explorer pane, and from the menu bar select View and then Refresh. |
To detach a database
-
Connect to the Database Engine.
-
From the Standard bar, click New Query.
-
Copy and paste the following example into the query window and click Execute. This example detaches the AdventureWorks2012 database with skipchecks set to true.
EXEC sp_detach_db 'AdventureWorks2012', 'true';
