sp_addmergepullsubscription (Transact-SQL)

適用対象: SQL ServerAzure SQL Managed Instance

マージ パブリケーションにプル サブスクリプションを追加します。 このストアド プロシージャは、サブスクリプション データベースのサブスクライバーで実行されます。

Transact-SQL 構文表記規則

構文

sp_addmergepullsubscription
    [ @publication = ] N'publication'
    [ , [ @publisher = ] N'publisher' ]
    [ , [ @publisher_db = ] N'publisher_db' ]
    [ , [ @subscriber_type = ] N'subscriber_type' ]
    [ , [ @subscription_priority = ] subscription_priority ]
    [ , [ @sync_type = ] N'sync_type' ]
    [ , [ @description = ] N'description' ]
[ ; ]

引数

[ @publication = ] N'publication'

出版物の名前。 @publicationは sysname で、既定値はありません。

[ @publisher = ] N'publisher'

パブリッシャーの名前。 @publisherは sysname で、既定値はローカル サーバー名です。 パブリッシャーは有効なサーバーである必要があります。

[ @publisher_db = ] N'publisher_db'

パブリッシャー データベースの名前。 @publisher_dbは sysname で、既定値は NULL.

[ @subscriber_type = ] N'subscriber_type'

サブスクライバーの種類。 @subscriber_typeは nvarchar(15) で、既定値は localgloballocalまたは anonymous. SQL Server 2005 (9.x) 以降のバージョンでは、ローカル サブスクリプションはクライアント サブスクリプションと呼ばれ、グローバル サブスクリプションはサーバー サブスクリプションと呼ばれます

[ @subscription_priority = ] subscription_priority

サブスクリプションの優先度。 @subscription_priorityは実際の値で、既定値は NULL. ローカル サブスクリプションと匿名サブスクリプションの場合、優先度は 0.0. 競合が検出されたときに勝者を選択するために、既定の競合回避モジュールによって優先順位が使用されます。 グローバル サブスクライバーの場合、サブスクリプションの優先度はパブリッシャーの優先順位であるよりも小さく 100する必要があります。

[ @sync_type = ] N'sync_type'

サブスクリプション同期の種類。 @sync_typeは nvarchar(15) で、既定値は automatic. automatic または none を指定できます。 この場合 automatic、パブリッシュされたテーブルのスキーマと初期データが最初にサブスクライバーに転送されます。 この場合 none、サブスクライバーはパブリッシュされたテーブルのスキーマと初期データを既に持っていると見なされます。 システム テーブルとデータは常に転送されます。

の値 automaticを指定することをお勧めします。

[ @description = ] N'description'

このプル サブスクリプションの簡単な説明。 @descriptionは nvarchar(255) で、既定値は NULL. この値は、レプリケーション モニターによって列に Friendly Name 表示されます。この列を使用して、監視対象のパブリケーションのサブスクリプションを並べ替えることができます。

リターン コードの値

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

解説

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

SQL Server エージェントを使用してサブスクリプションを同期する場合は、サブスクライバーでsp_addmergepullsubscription_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".

-- Execute this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @hostname AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2022';
SET @hostname = N'adventure-works\david8';

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorks2022Replica]
EXEC sp_addmergepullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription. 
EXEC sp_addmergepullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication, 
  @distributor = @publisher, 
  @job_login = $(Login), 
  @job_password = $(Password),
  @hostname = @hostname;
GO
-- 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".

-- Publication must support anonymous Subscribers.
-- Execute this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @websyncurl AS sysname;
DECLARE @security_mode AS int;
DECLARE @login AS sysname;
DECLARE @password AS nvarchar(512);
SET @publication = N'AdvWorksSalesOrdersMergeWebSync';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2022';
SET @websyncurl = 'https://' + $(WebServer) + '/WebSync';
SET @security_mode = 0; -- Basic Authentication for IIS
SET @login = $(Login);
SET @password = $(Password);

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorks2022Replica]
EXEC sp_addmergepullsubscription 
    @publisher = @publisher, 
    @publication = @publication, 
    @publisher_db = @publicationDB,
    @subscriber_type = N'anonymous';

-- Add an agent job to synchronize the pull subscription. 
EXEC sp_addmergepullsubscription_agent 
    @publisher = @publisher, 
    @publisher_db = @publicationDB, 
    @publication = @publication, 
    @distributor = @publisher, 
    @job_login = @login, 
    @job_password = @password,
    @use_web_sync = 1,
    @internet_security_mode = @security_mode,
    @internet_url = @websyncurl,
    @internet_login = @login,
    @internet_password = @password;
GO

アクセス許可

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