sp_reinitmergesubscription (Transact-SQL)

标记一个合并订阅,以便在下一次运行合并代理时重新初始化。此存储过程可在发布服务器的任意发布数据库中执行。

主题链接图标Transact-SQL 语法约定

语法

sp_reinitmergesubscription [ [ @publication = ] 'publication'
    [ , [ @subscriber = ] 'subscriber'
    [ , [ @subscriber_db = ] 'subscriber_db'
    [ , [ @upload_first = ] 'upload_first'

参数

  • [ @publication = ] 'publication'
    发布的名称。publication 的数据类型为 sysname,默认值为 all
  • [ @subscriber=] 'subscriber'
    订阅服务器的名称。subscriber 的数据类型为 sysname,默认值为 all
  • [ @subscriber_db=] 'subscriber_db'
    订阅服务器数据库的名称。subscriber_db 的数据类型为 sysname,默认值为 all
  • [ @upload_first = ] 'upload_first'
    表示在重新初始化订阅之前是否上载订阅服务器上的更改。upload_first 的数据类型为 nvarchar(5),默认值为 FALSE。如果为 True,则在重新初始化订阅之前将上载更改。如果为 False,则不上载更改。

返回代码值

0(成功)或 1(失败)

备注

sp_reinitmergesubscription 用于合并复制。

可从发布服务器调用 sp_reinitmergesubscription,重新初始化合并订阅。建议同时重新运行快照代理。

如果添加、删除或更改参数化筛选器,在订阅服务器上挂起的更改在重新初始化期间将无法上载到发布服务器。若要上载挂起的更改,请在更改筛选器前同步所有订阅。

权限

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

示例

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

DECLARE @subscriptionDB AS sysname;
DECLARE @publication AS sysname;
SET @subscriptionDB = N'AdventureWorksReplica';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorksReplica]

-- Execute at the Publisher to reinitialize the push subscription. 
-- Pending changes at the Subscrber are lost.
EXEC sp_reinitmergesubscription 
    @subscriber = $(SubServer),
    @subscriber_db = @subscriptionDB,
    @publication = @publication,
    @upload_first = N'false';
GO

-- Start the Merge Agent.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

DECLARE @subscriptionDB AS sysname;
DECLARE @publication AS sysname;
SET @subscriptionDB = N'AdventureWorksReplica';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorksReplica]

-- Execute at the Publisher to reinitialize the push subscription, 
-- and upload pending changes at the Subscriber. 
EXEC sp_reinitmergesubscription 
    @subscriber = $(SubServer),
    @subscriber_db = @subscriptionDB,
    @publication = @publication,
    @upload_first = N'true';
GO

-- Start the Merge Agent.

请参阅

参考

系统存储过程 (Transact-SQL)

其他资源

How to: Reinitialize a Subscription (Replication Transact-SQL Programming)
重新初始化订阅

帮助和信息

获取 SQL Server 2005 帮助