Attaches a database that has only one data file to the current server. sp_attach_single_file_db cannot be used with multiple data files.
Transact-SQL Syntax Conventions
sp_attach_single_file_db [ @dbname= ] 'dbname' , [ @physname= ] 'physical_name'
Is the name of the database to be attached to the server. The name must be unique. dbname is sysname, with a default of NULL.
Is the physical name, including path, of the database file. physical_name is nvarchar(260), with a default of NULL.
When you attach a SQL Server 2005 database that contains full-text catalog files onto a SQL Server 2008 server instance, the catalog files are attached from their previous location along with the other database files, the same as in SQL Server 2005. For more information, see Full-Text Search Upgrade.
0 (success) or 1 (failure)
None
Use sp_attach_single_file_db only on databases that were previously detached from the server by using an explicit sp_detach_db operation or on copied databases.
sp_attach_single_file_db works only on databases that have a single log file. When sp_attach_single_file_db attaches the database to the server, it builds a new log file. If the database is read-only, the log file is built in its previous location.
Do not use this procedure on a replicated database.
For information about how permissions are handled when a database is attached, see CREATE DATABASE (Transact-SQL).
The following example detaches AdventureWorks and then attaches one file from AdventureWorks to the current server.
AdventureWorks
USE master; GO EXEC sp_detach_db @dbname = 'AdventureWorks'; EXEC sp_attach_single_file_db @dbname = 'AdventureWorks', @physname = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\AdventureWorks_Data.mdf';