次の方法で共有


sp_addmergepullsubscription (Transact-SQL)

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

トピック リンク アイコンTransact-SQL 構文表記規則

構文

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

引数

  • [ @publication=] 'publication'
    パブリケーションの名前を指定します。publication のデータ型は sysname で、既定値はありません。

  • [ @publisher = ] 'publisher'
    パブリッシャの名前を指定します。Publisher のデータ型は sysname で、既定値はローカル サーバー名です。パブリッシャは有効なサーバーであることが必要です。

  • [ @publisher_db=] 'publisher_db'
    パブリッシャ データベースの名前を指定します。publisher_db のデータ型は sysname で、既定値は NULL です。

  • [ @subscriber_type=] 'subscriber_type'
    サブスクライバの種類を指定します。subscriber_type のデータ型は nvarchar(15) で、globallocal、または anonymous を指定できます。SQL Server 2005 以降のバージョンでは、ローカル サブスクリプションはクライアント サブスクリプションと呼ばれ、グローバル サブスクリプションはサーバー サブスクリプションと呼ばれます。詳細については、「マージ レプリケーションで競合を検出および解決する方法」の「サブスクリプションの種類」を参照してください。

  • [ @subscription_priority=] subscription_priority
    サブスクリプションの優先度です。subscription_priority のデータ型は real で、既定値は NULL です。ローカル サブスクリプションと匿名サブスクリプションの場合、優先度は 0.0 になります。優先度は、競合の検出時、既定の競合回避モジュールによって実行される操作を選択する場合に使用されます。グローバル サブスクライバの場合、サブスクリプション優先度をパブリッシャの優先度である 100 未満にする必要があります。

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

    注意

    none を指定することはお勧めしません。詳細については、「スナップショットを使用しないマージ サブスクリプションの初期化」を参照してください。

  • [ @description =] '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'AdventureWorks2008R2';
SET @hostname = N'adventure-works\david8';

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorks2008R2Replica]
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'AdventureWorks2008R2';
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 [AdventureWorks2008R2Replica]
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

権限

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