Share via


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できます。