sp_mergearticlecolumn (Transact-SQL)

适用于:SQL Server

对合并发布进行垂直分区。 此存储过程在发布服务器上对发布数据库执行。

Transact-SQL 语法约定

语法

sp_mergearticlecolumn
    [ @publication = ] N'publication'
    , [ @article = ] N'article'
    [ , [ @column = ] N'column' ]
    [ , [ @operation = ] N'operation' ]
    [ , [ @schema_replication = ] N'schema_replication' ]
    [ , [ @force_invalidate_snapshot = ] force_invalidate_snapshot ]
    [ , [ @force_reinit_subscription = ] force_reinit_subscription ]
[ ; ]

参数

[ @publication = ] N'publication'

发布的名称。 @publicationsysname,无默认值。

[ @article = ] N'article'

出版物中项目的名称。 @articlesysname,无默认值。

[ @column = ] N'column'

标识要在其中创建垂直分区的列。 @column为 sysname,默认值为 NULL. 如果NULL设置为@operation add,则默认情况下,源表中的所有列都会添加到项目。 当@operation设置为@column,无法NULL@columndrop。 若要从项目中排除列,请执行sp_mergearticlecolumn并指定@column,并设置为@operationdrop要从指定@article中删除的每个列。

[ @operation = ] N'operation'

副本 (replica)tion 状态。 @operation为 nvarchar(4),默认值为 add.

  • add标记要副本 (replica)的列。
  • drop 清除列。

[ @schema_replication = ] N'schema_副本 (replica)tion'

指定在运行合并代理时传播架构更改。 @schema_副本 (replica)tionnvarchar(5),默认值为 false.

false支持@schema_副本 (replica)。

[ @force_invalidate_snapshot = ] force_invalidate_快照

启用或禁用使快照失效的功能。 @force_invalidate_快照为,默认值为 0.

  • 0指定对合并项目所做的更改不会导致快照无效。

  • 1指定对合并项目所做的更改可能会导致快照无效,如果是这样,则表示新快照发生权限的值1

[ @force_reinit_subscription = ] force_reinit_subscription

启用或禁用重新初始化订阅的功能。 @force_reinit_subscription为,默认值为 0.

  • 0 指定对合并项目所做的更改不会导致重新初始化订阅。

  • 1 指定对合并项目所做的更改可能会导致重新初始化订阅,如果是这种情况,则表示订阅重新初始化的权限的值 1

返回代码值

0(成功)或 1(失败)。

注解

sp_mergearticlecolumn用于合并副本 (replica)。

如果使用自动标识范围管理,则无法从项目中删除标识列。 有关详细信息,请参阅复制标识列

如果创建初始快照后,应用程序设置了新的垂直分区,则一定会生成新的快照且重新应用于每个订阅。 当下一个已计划的快照和分发或合并代理运行时应用快照。

如果行跟踪用于冲突检测(默认值),则基表最多可包含 1,024 列,但是必须从项目中筛选列,以便最多发布 246 列。 如果使用列跟踪,则基表最多可包含 246 列。

示例

DECLARE @publication AS sysname;
DECLARE @table1 AS sysname;
DECLARE @table2 AS sysname;
DECLARE @table3 AS sysname;
DECLARE @salesschema AS sysname;
DECLARE @hrschema AS sysname;
DECLARE @filterclause AS nvarchar(1000);
SET @publication = N'AdvWorksSalesOrdersMerge'; 
SET @table1 = N'Employee'; 
SET @table2 = N'SalesOrderHeader'; 
SET @table3 = N'SalesOrderDetail'; 
SET @salesschema = N'Sales';
SET @hrschema = N'HumanResources';
SET @filterclause = N'Employee.LoginID = HOST_NAME()';

-- Add a filtered article for the Employee table.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table1, 
  @source_object = @table1, 
  @type = N'table', 
  @source_owner = @hrschema,
  @schema_option = 0x0004CF1,
  @description = N'article for the Employee table',
  @subset_filterclause = @filterclause;

-- Add an article for the SalesOrderHeader table that is filtered
-- based on Employee and horizontally filtered.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table2, 
  @source_object = @table2, 
  @type = N'table', 
  @source_owner = @salesschema, 
  @vertical_partition = N'true',
  @schema_option = 0x0034EF1,
  @description = N'article for the SalesOrderDetail table';

-- Add an article for the SalesOrderDetail table that is filtered
-- based on SaledOrderHeader.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table3, 
  @source_object = @table3, 
  @source_owner = @salesschema,
  @description = 'article for the SalesOrderHeader table', 
  @identityrangemanagementoption = N'auto', 
  @pub_identity_range = 100000, 
  @identity_range = 100, 
  @threshold = 80,
  @schema_option = 0x0004EF1;

-- Add all columns to the SalesOrderHeader article.
EXEC sp_mergearticlecolumn 
  @publication = @publication, 
  @article = @table2, 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Remove the credit card Approval Code column.
EXEC sp_mergearticlecolumn 
  @publication = @publication, 
  @article = @table2, 
  @column = N'CreditCardApprovalCode', 
  @operation = N'drop', 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Add a merge join filter between Employee and SalesOrderHeader.
EXEC sp_addmergefilter 
  @publication = @publication, 
  @article = @table2, 
  @filtername = N'SalesOrderHeader_Employee', 
  @join_articlename = @table1, 
  @join_filterclause = N'Employee.BusinessEntityID = SalesOrderHeader.SalesPersonID', 
  @join_unique_key = 1, 
  @filter_type = 1, 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Add a merge join filter between SalesOrderHeader and SalesOrderDetail.
EXEC sp_addmergefilter 
  @publication = @publication, 
  @article = @table3, 
  @filtername = N'SalesOrderDetail_SalesOrderHeader', 
  @join_articlename = @table2, 
  @join_filterclause = N'SalesOrderHeader.SalesOrderID = SalesOrderDetail.SalesOrderID', 
  @join_unique_key = 1, 
  @filter_type = 1, 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;
GO

权限

只有 sysadmin 固定服务器角色的成员db_owner固定数据库角色的成员才能执行sp_mergearticlecolumn