Export (0) Print
Expand All
Expand Minimize

sp_detach_db

SQL Server 2000

  Topic last updated -- July 2003

Detaches a database from a server and, optionally, runs UPDATE STATISTICS on all tables before detaching.

Important  For a replicated database to be detached, it must be unpublished.

Syntax

sp_detach_db [ @dbname = ] 'dbname'
    
[ , [ @skipchecks = ] 'skipchecks' ]

Arguments

[@dbname =] 'dbname'

Is the name of the database to be detached. dbname is sysname, with a default value of NULL.

[@skipchecks =] 'skipchecks'

skipchecks is nvarchar(10), with a default value of NULL. If true, UPDATE STATISTICS is skipped. If false, UPDATE STATISTICS is run. This option is useful for databases that are to be moved to read-only media.

Return Code Values

0 (success) or 1 (failure)

Result Sets

None

Remarks

The detached files remain and can be reattached using sp_attach_db or sp_attach_single_file_db. The files can also be moved to another server and attached.

Permissions

Only members of the sysadmin fixed server role can execute sp_detach_db.

Examples

This example detaches the pubs database with skipchecks set to true.

EXEC sp_detach_db 'pubs', 'true'

See Also

sp_attach_db

sp_attach_single_file_db

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft