sp_reinitmergesubscription (Transact-SQL)

適用対象:SQL Server

マージ エージェントの次回実行時に再初期化するように、マージ サブスクリプションにマークを付けます。 このストアド プロシージャは、パブリッシャー側のパブリケーション データベースで実行されます。

Transact-SQL 構文表記規則

構文

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

引数

[ @publication = ] N'publication'

出版物の名前。 @publicationは sysname で、既定値は all.

[ @subscriber = ] N'subscriber'

サブスクライバーの名前。 @subscriberは sysname で、既定値は all.

[ @subscriber_db = ] N'subscriber_db'

サブスクライバー データベースの名前。 @subscriber_dbは sysname で、既定値は all.

[ @upload_first = ] N'upload_first'

サブスクリプションを再初期化する前にサブスクライバーの変更をアップロードするかどうかを指定します。 @upload_firstは nvarchar(5) で、既定値は false.

  • 場合 trueは、サブスクリプションが再初期化される前に変更がアップロードされます。
  • の場合 false、変更はアップロードされません。

リターン コードの値

0 (成功) または 1 (失敗)。

解説

sp_reinitmergesubscription はマージ レプリケーションで使用されます。

sp_reinitmergesubscription は、マージ サブスクリプションを再初期化するためにパブリッシャーから呼び出すことができます。 スナップショット エージェントも再実行する必要があります。

パラメーター化されたフィルターを追加、削除、または変更した場合、サブスクライバーで保留中の変更を再初期化中にパブリッシャーにアップロードすることはできません。 保留中の変更をアップロードしたい場合は、フィルターを変更する前にすべてのサブスクリプションを同期してください。

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

USE [AdventureWorks2022Replica]

-- 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.

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

USE [AdventureWorks2022Replica]

-- 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.

アクセス許可

sysadmin 固定サーバー ロールまたは固定データベース ロールdb_ownerのメンバーのみが実行sp_reinitmergesubscriptionできます。