sp_attach_single_file_db (T-SQL)

Attaches a database having only one data file to the current server.

Syntax

sp_attach_single_file_db [@dbname =] 'dbname',
    
[@physname =] 'physical_name'

Arguments
[@dbname =] 'dbname'
Is the name of the database to be attached to the server. dbname is sysname, with a default of NULL.
[@physname =] 'phsyical_name'
Is the physical name, including path, of the database file. physical_name is nvarchar(260), with a default of NULL.
Return Code Values

0 (success) or 1 (failure)

Result Sets

None

Remarks

When sp_attach_single_file_db attaches the database to the server, it builds a new log file and performs additional cleanup work to remove replication from the newly-attached database.

Used sp_attach_single_file_db only on databases that were previously detached from the server using an explicit sp_detach_db operation.

Permissions

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

Examples

This example detaches pubs and then attaches one file from pubs to the current server.

EXEC sp_detach_db @dbname = 'pubs'

EXEC sp_attach_single_file_db @dbname = 'pubs',
    @physname = 'c:\mssql7\data\pubs.mdf'

  

See Also
sp_attach_db sp_helpfile
sp_detach_db System Stored Procedures

  


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