Attaches a database to a server.
sp_attach_db [@dbname =] 'dbname',
[@filename1 =] 'filename_n' [,...16]
0 (success) or 1 (failure)
None
sp_attach_db should only be executed on databases that were previously detached from the database server using an explicit sp_detach_db operation. If more than 16 files must be specified, use CREATE DATABASE with the FOR ATTACH clause.
If you attach a database to a server other than the server from which the database was detached, and the detached database was enabled for replication, you should run sp_removedbreplication to remove replication from the database.
Only by members of the sysadmin fixed server role can execute sp_attach_db.
This example attaches two files from pubs to the current server.
EXEC sp_attach_db @dbname = N'pubs',
@filename1 = N'c:\mssql7\data\pubs.mdf',
@filename2 = N'c:\mssql7\data\pubs_log.ldf'
CREATE DATABASE | sp_helpfile |
sp_attach_single_file_db | sp_removedbreplication |
sp_detach_db | System Stored Procedures |