sp_repladdcolumn (Transact-SQL)sp_repladdcolumn (Transact-SQL)

本主題適用於:是SQL Server (從 2008 開始)否Azure SQL Database否Azure SQL 資料倉儲 否平行處理資料倉儲 THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)noAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

將資料行加入已發行的現有資料表發行項中。Adds a column to an existing table article that has been published. 它可讓您將新資料行加入發行這份資料表的所有發行者中,或只將資料行加入發行這份資料表的特定發行集。Allows the new column to be added to all publishers that publish this table, or just add the column to a specific publication that publishes the table. 這個預存程序執行於發行集資料庫的發行者端。This stored procedure is executed at the Publisher on the publication database.

重要

這個預存程序已被取代,支援它的目的是為了回溯相容性。This stored procedure has been deprecated and is being supported for backward-compatibility. 它應該只用於具有 MicrosoftMicrosoft SQL Server 2000SQL Server 2000發行者和 SQL Server 2000SQL Server 2000重新發行訂閱者。It should only be used with MicrosoftMicrosoft SQL Server 2000SQL Server 2000 Publishers and SQL Server 2000SQL Server 2000 republishing Subscribers. 這個程序不應該用於含有 SQL Server 2005SQL Server 2005 或更高版本中導入之資料類型的資料行。This procedure should not be used on columns with data types that were introduced in SQL Server 2005SQL Server 2005 or higher.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax


sp_repladdcolumn [ @source_object = ] 'source_object', [ @column = ] 'column' ]  
    [ , [ @typetext = ] 'typetext' ]  
    [ , [ @publication_to_add = ] 'publication_to_add' ]  
    [ , [ @from_agent = ] from_agent ]  
    [ , [ @schema_change_script = ] 'schema_change_script' ]  
    [ , [ @force_invalidate_snapshot = ] force_invalidate_snapshot ]  
    [ , [ @force_reinit_subscription = ] force_reinit_subscription ]  

引數Arguments

[ @source_object =] 'source_object'[ @source_object =] 'source_object'
這是包含要加入之新資料行的資料表發行項名稱。Is the name of the table article that contains the new column to add. source_objectnvarchar (358),沒有預設值。source_object is nvarchar(358), with no default.

[ @column =] '資料行'[ @column =] 'column'
這是複寫要加入之資料表中的資料行名稱。Is the name of the column in the table to be added for replication. 資料行sysname,沒有預設值。column is sysname, with no default.

[ @typetext =] 'typetext'[ @typetext =] 'typetext'
這是要加入之資料行的定義。Is the definition of the column being added. typetextnvarchar (3000),沒有預設值。typetext is nvarchar(3000), with no default. 例如,如果要加入資料行,而且它是單一字元欄位時,不是 NULL,且預設值為N,order_filled 就是資料行參數,而的定義資料行, char (1) NOT NULL CONSTRAINT constraint_name DEFAULT 'n'typetext參數值。For example, if the column order_filled is being added, and it is a single character field, not NULL, and has a default value of N, order_filled would be the column parameter, while the definition of the column, char(1) NOT NULL CONSTRAINT constraint_name DEFAULT 'N' would be the typetext parameter value.

[ @publication_to_add =] 'publication_to_add'[ @publication_to_add =] 'publication_to_add'
這是新資料行要加入其中的發行集名稱。Is the name of the publication to which the new column is added. publication_to_addnvarchar (4000),預設值是所有publication_to_add is nvarchar(4000), with a default of ALL. 如果所有,則所有發行集包含此資料表會受到影響。If ALL, then all publications containing this table are affected. 如果publication_to_add指定,則此發行集已加入新的資料行。If publication_to_add is specified, then only this publication has the new column added.

[ @from_agent =] from_agent[ @from_agent = ] from_agent
預存程序是否由複寫代理程式執行。If the stored procedure is being executed by a replication agent. from_agentint,預設值是0,其中值為1複寫代理程式,並在正在執行此預存程序時,會使用每個其他情況下的預設值0應使用。from_agent is int, with a default of 0, where a value of 1 is used when this stored procedure is being executed by a replication agent, and in every other case the default value of 0should be used.

[ @schema_change_script =] 'schema_change_script'[ @schema_change_script =] 'schema_change_script'
指定用來修改系統產生之自訂預存程序的 SQL ServerSQL Server 指令碼的名稱和路徑。Specifies the name and path of a SQL ServerSQL Server script used to modify the system generated custom stored procedures. schema_change_scriptnvarchar (4000),預設值是 NULL。schema_change_script is nvarchar(4000), with a default of NULL. 複寫可讓使用者自訂的自訂預存程序,取代異動複寫所用的一個或多個預設程序。Replication allows user-defined custom stored procedures to replace one or more of the default procedures used in transactional replication. schema_change_script執行後結構描述變更複寫的資料表發行項使用 sp_repladdcolumn 時,會進行,可用來執行下列其中一項:schema_change_script is executed after a schema change is made to a replicated table article using sp_repladdcolumn, and can be used to do one of the following:

  • 如果自動重新產生自訂的預存程序, schema_change_script可用來卸除這些自訂預存程序,並取代為使用者定義自訂預存程序可支援新的結構描述。If custom stored procedures are automatically regenerated, schema_change_script can be used to drop these custom stored procedures and replace them with user-defined custom stored procedures that supports the new schema.

  • 如果無法自動重新產生自訂預存程序, schema_change_script可用來重新產生這些預存程序,或建立使用者定義的自訂預存程序。If custom stored procedures are not automatically regenerated, schema_change_scriptcan be used to regenerate these stored procedures or to create user-defined custom stored procedures.

    [ @force_invalidate_snapshot =] force_invalidate_snapshot[ @force_invalidate_snapshot = ] force_invalidate_snapshot
    啟用或停用使快照集失效的能力。Enables or disables the ability to have a snapshot invalidated. force_invalidate_snapshot,預設值是1force_invalidate_snapshot is a bit, with a default of 1.

    1指定發行項的變更可能使快照集失效,如果這種情況下,值為和1提供將出現新的快照集的權限。1 specifies that changes to the article may cause the snapshot to be invalid, and if that is the case, a value of 1 gives permission for the new snapshot to occur.

    0指定發行項的變更不會使快照集失效。0 specifies that changes to the article do not cause the snapshot to be invalid.

    [ @force_reinit_subscription =] force_reinit_subscription[ @force_reinit_subscription = ] force_reinit_subscription
    啟用或停用重新初始化訂閱的能力。Enables or disables the ability to have the subscription reinitializated. force_reinit_subscription預設值是0force_reinit_subscription is a bit with a default of 0.

    0指定發行項的變更不會使訂閱重新初始化。0 specifies that changes to the article do not cause the subscription to be reinitialized.

    1指定發行項的變更可能使訂閱重新初始化,以及如果這種情況下,值為1提供發生訂閱重新初始化的權限。1 specifies that changes to the article may cause the subscription to be reinitialized, and if that is the case, a value of 1 gives permission for the subscription reinitialization to occur.

傳回碼值Return Code Values

0 (成功) 或 1 (失敗)0 (success) or 1 (failure)

PermissionsPermissions

只有系統管理員 (sysadmin) 固定伺服器角色和 db_owner 固定資料庫角色的成員,才能夠執行 sp_repladdcolumn。Only members of the sysadmin fixed server role and the db_owner fixed database role can execute sp_repladdcolumn.

請參閱<See Also

SQL Server 複寫中已被取代的功能 Deprecated Features in SQL Server Replication
系統預存程序 (Transact-SQL)System Stored Procedures (Transact-SQL)