次の方法で共有


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 をパブリッシャーから呼び出して、マージ サブスクリプションを再初期化できます。 その際には、スナップショット エージェントも再実行することをお勧めします。

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

使用例

-- 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'AdventureWorks2012Replica';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2012Replica]

-- 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'AdventureWorks2012Replica';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2012Replica]

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

権限

sp_reinitmergesubscription を実行できるのは、固定サーバー ロール sysadmin または固定データベース ロール db_owner のメンバーだけです。

関連項目

参照

システム ストアド プロシージャ (Transact-SQL)

概念

サブスクリプションの再初期化