sp_reinitmergepullsubscription (Transact-SQL)

适用于SQL Server

将合并请求订阅标记为在下次运行合并代理时重新初始化。 此存储过程在订阅服务器上针对订阅数据库执行。

Transact-SQL 语法约定

语法

sp_reinitmergepullsubscription
    [ [ @publisher = ] N'publisher' ]
    [ , [ @publisher_db = ] N'publisher_db' ]
    [ , [ @publication = ] N'publication' ]
    [ , [ @upload_first = ] N'upload_first' ]
[ ; ]

参数

[ @publisher = ] N'publisher'

发布服务器的名称。 @publisher为 sysname,默认值为 all.

[ @publisher_db = ] N'publisher_db'

发布服务器数据库的名称。 @publisher_db为 sysname,默认值为 all.

[ @publication = ] N'publication'

发布的名称。 @publication为 sysname,默认值为 all.

[ @upload_first = ] N'upload_first'

指定在重新初始化订阅之前是否上传订阅中的更改。 @upload_first为 nvarchar(5),默认值为 false.

  • 如果在 true重新初始化订阅之前上传更改。
  • 如果 false,则不会上传更改。

返回代码值

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

注解

sp_reinitmergepullsubscription 用于合并复制。

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

示例

A. 重新初始化请求订阅并丢失挂起的更改

-- 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 @publicationDB AS sysname;
DECLARE @publication AS sysname;
SET @publicationDB = N'AdventureWorks2022';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2022Replica]

-- Execute at the Subscriber to reinitialize the pull subscription. 
-- Pending changes at the Subscrber are lost.
EXEC sp_reinitmergepullsubscription 
    @publisher = $(PubServer),
    @publisher_db = @publicationDB,
    @publication = @publication,
    @upload_first = N'false';
GO

-- Start the Merge Agent.

B. 重新初始化请求订阅并上传挂起的更改

-- 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 @publicationDB AS sysname;
DECLARE @publication AS sysname;
SET @publicationDB = N'AdventureWorks2022';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2022Replica]

-- Execute at the Subscriber to reinitialize the pull subscription, 
-- and upload pending changes at the Subscriber. 
EXEC sp_reinitmergepullsubscription 
    @publisher = $(PubServer),
    @publisher_db = @publicationDB,
    @publication = @publication,
    @upload_first = N'true';
GO

-- Start the Merge Agent.

权限

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