Detaches a database from a server and, optionally, runs UPDATE STATISTICS on all tables before detaching.
sp_detach_db [ @dbname = ] 'dbname'
[ , [ @skipchecks = ] 'skipchecks' ]
[@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.
0 (success) or 1 (failure)
None
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.
Only members of the sysadmin fixed server role can execute sp_detach_db.
This example detaches the pubs database with skipchecks set to true.
EXEC sp_detach_db 'pubs', 'true'