DetachDB Method (SQL-DMO)

The DetachDB method makes a database invisible to a Microsoft® SQL Server™ installation.

Applies To

SQLServer Object

Syntax

object.DetachDB( DBName [, bCheck ] ) as String

Part Description
object Expression that evaluates to an object in the Applies To list.
DBName String specifying an existing, attached database by name.
bCheck Optional. When True (default), statistics supporting query optimization are updated prior to the detach operation. When False, statistics are not updated prior to the detach operation.

Returns

A string containing status or error message detail.

Remarks

SQL Server implements database detach and attach operations to allow relocation of the operating system files implementing storage for the database and its transaction log. When the database is detached, the files can be moved without negatively affecting the SQL Server installation.


Important Ensure that bCheck is True when detaching a database for which statistics cannot be updated in the future. For example, databases that will be implemented on read-only media such as CD-ROM should always have query optimization statistics updated as the last step before the detach operations.


For more information about attaching a detached database by using SQL-DMO, see AttachDB Method and AttachDBWithSingleFile Method.

Making a database invisible to a SQL Server installation by using the DetachDB method requires appropriate privilege. The SQL Server login used for SQLServer object connection must be a member of the system-defined role sysadmin.

Prototype (C/C++)

HRESULT DetachDB(SQLDMO_LPCSTR DBName,
SQLDMO_LPBSTR pResult,
BOOL bCheck = TRUE);

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.