Code line additional detached Database

Source: Internet
Author: User
Additional database sp_attach_db

Attach the database to the server.

Syntax

Sp_attach_db[@ Dbname =]'Dbname'
,
[@ Filename1 =]'Filename_n'[,...16]

Parameters

[@ Dbname =]'Dbname'

Name of the database to be appended to the server. The name must be unique.DbnameThe data type of isSysnameThe default value is null.

[@ Filename1 =]'Filename_n'

The physical name of the database file, including the path.Filename_nThe data type of isNvarchar (260)The default value is null. A maximum of 16 file names can be specified. The parameter name is@ Filename1Starts and increments@ Filename16. The file name list must contain at least the primary file. The primary file contains the system tables pointing to other files in the database. The list must also contain all the files that are moved after the database is detached.

Only explicitSp_detach_dbPerform operations on databases separated from the Database ServerSp_attach_db. If you must specify more than 16 files, use the create database with the for attach clause.

If the server to which the database is appended is not the server from which the database is detached and the detached database is enabled for replication, runSp_removedbreplicationDelete a copy from a database.

Permission

OnlySysAdminAndDbcreatorOnly members with fixed server roles can perform this process.

Example

In the following examplePubsTo 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'
 
 Detaching a database sp_detach_db

Detach the database from the server, and you can choose to run update statistics on all tables before the separation.

Syntax

Sp_detach_db[@ Dbname =]'Dbname'
[,[@ Skipchecks =]'Skipchecks']

Parameters

[@ Dbname =]'Dbname'

Name of the database to be detached.DbnameThe data type of isSysnameThe default value is null.

[@ Skipchecks =]'Skipchecks'

SkipchecksThe data type of isNvarchar (10)The default value is null. IfTrue, The update statistics is skipped. IfFalseTo run update statistics. This option is useful for databases to be moved to read-only media.

Note

UseSp_attach_dbOrSp_attach_single_file_dbRetain and re-append the detached file. Files can also be moved and appended to other servers.

Permission

OnlySysAdminMembers with fixed server roles can only executeSp_detach_db.

Example

The following example separatesPubsDatabase, andSkipchecksSetTrue.

 
Exec sp_detach_db 'pubs', 'true'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.