This topic describes how to detach a database using dbForge Studio for SQL Server.
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, be aware of the following limitations:
You must be a member of the sysadmin or db_owner role.
When moving a database, check the files associated with it and their current locations by querying the sys.database_files system catalog view before detaching it from the existing SQL Server instance:
SELECT type_desc, name, physical_name
FROM sys.database_files;
where:
type_desc – The description of the file type: ROWS, LOG, FILESTREAM, and FULLTEXT.name – The logical name of the file in the database.physical_name – The operating-system file name.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 following options:
Note
By default, outdated optimization statistics are retained during the detach operation.
4. To view the script of the detached database, in the left-lower corner of the dialog, click Script changes, then select one of these options:
The script may be as follows:
USE [master]
GO
EXEC master.dbo.sp_detach_db @dbname = N'<database_name>'
GO
where:
<database_name> – The name of the database you want to detach.5. Click OK to detach the database.
After the database is detached, the Status column displays the
icon.

5. Click Close to close the dialog.
1. In Database Explorer, press and hold down Ctrl, then select the required databases.
2. Right-click the databases and select Tasks > Detach Database.
3. In the Detach Database dialog, select the checkboxes for the required options, then click OK.
4. Click Close to close the dialog.
If the database fails to detach, hover over the
icon in the Status column to view the error details.

You can detach a database using the sp_detach_db system stored procedure.
To detach a database using sp_detach_db:
1. On the SQL toolbar, click New SQL to open a new SQL document.
2. Enter the following command and replace the argument with your database name:
EXEC sp_detach_db @dbname = 'database_name';
where:
database_name – The name of the database you want to detach.3. On the SQL toolbar, click Execute, or press F5.
After the command runs successfully, the database is removed from the SQL Server instance, but the physical files remain in their original locations.