database-->所有任务——>attach database

解决方案 »

  1.   

    Syntax
    sp_attach_db [ @dbname = ] 'dbname' 
        , [ @filename1 = ] 'filename_n' [ ,...16 ] Arguments
    [@dbname =] 'dbname'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. [@filename1 =] 'filename_n'Is the physical name, including path, of a database file. filename_n is nvarchar(260), with a default of NULL. There can be up to 16 file names specified. The parameter names start at @filename1 and increment to @filename16. The file name list must include at least the primary file, which contains the system tables that point to other files in the database. The list must also include any files that were moved after the database was detached.Return Code Values
    0 (success) or 1 (failure)Result Sets
    NoneRes
    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.Permissions
    Only members of the sysadmin and dbcreator fixed server roles can execute this procedure.Examples
    This example attaches two files from pubs to the current server.EXEC sp_attach_db @dbname = N'pubs', 
       @filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf', 
       @filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'
      

  2.   

    Thanks All!
    Especially thanks for xuam() !to xuam() 
    我也喜欢多使用英文,
    但限于自己英文水平,超过100个单词我就晕!@_@! 呵!
      

  3.   

    EXEC sp_attach_db @dbname = N'new_db', 
       @filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf', 
       @filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.ldf