Share via


sp_addmergepullsubscription (Transact-SQL)

更新 : 2007 年 9 月 15 日

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

トピック リンク アイコン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 では、ローカル サブスクリプションはクライアント サブスクリプションと呼ばれ、グローバル サブスクリプションはサーバー サブスクリプションと呼ばれます。詳細については、「マージ レプリケーションで競合を検出および解決する方法」の「サブスクリプションの種類」を参照してください。パブリッシャでサブスクリプションを登録せずにサブスクリプションを作成する場合は、値 anonymous が必要です。これは、Web 同期など、サブスクリプションの構成中にパブリッシャへ SQL Server 接続を確立できない場合に対応するためです。
  • [ @subscription_priority=] subscription_priority
    サブスクリプションの優先度です。subscription_priority のデータ型は real で、既定値は NULL です。ローカル サブスクリプションと匿名サブスクリプションの場合、優先度は 0.0 になります。優先度は、競合の検出時、既定の競合回避モジュールによって実行される操作を選択する場合に使用されます。グローバル サブスクライバの場合、サブスクリプション優先度をパブリッシャの優先度である 100 未満にする必要があります。
  • [ @sync_type=] 'sync_type'
    サブスクリプションの同期の種類を指定します。sync_type のデータ型は nvarchar(15) で、既定値は automatic です。automatic または none を指定できます。automatic を指定した場合は、最初に、パブリッシュされたテーブルのスキーマと初期データがサブスクライバに転送されます。none を指定した場合は、パブリッシュされたテーブルのスキーマと初期データがサブスクライバに既に存在すると見なされます。システム テーブルとデータは常に転送されます。

    ms189456.note(ja-jp,SQL.90).gifメモ :
    none を指定することはお勧めしません。詳細については、「スナップショットを使用しないマージ サブスクリプションの初期化」を参照してください。
  • [ @description =] 'description'
    対象となるプル サブスクリプションの短い説明を指定します。descriptionのデータ型は nvarchar(255) で、既定値は NULL です。この値はレプリケーション モニタの Friendly Name 列に表示され、監視されるパブリケーションのサブスクリプションの並べ替えに使用できます。

解説

sp_addmergepullsubscription は、マージ レプリケーションで使用します。

SQL Server エージェントを使用してサブスクリプションを同期する場合は、サブスクライバ側で sp_addmergepullsubscription_agent ストアド プロシージャを実行し、パブリケーションと同期する、エージェントおよびジョブを作成する必要があります。

権限

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

戻り値

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

使用例

-- 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'AdventureWorks';
SET @hostname = N'adventure-works\david8';

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorksReplica]
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'AdventureWorks';
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 [AdventureWorksReplica]
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_agent (Transact-SQL)
sp_changemergepullsubscription (Transact-SQL)
sp_dropmergepullsubscription (Transact-SQL)
sp_helpmergepullsubscription (Transact-SQL)
sp_helpsubscription_properties (Transact-SQL)

その他の技術情報

プル サブスクリプションを作成する方法 (レプリケーション Transact-SQL プログラミング)
パブリケーションのサブスクライブ

ヘルプおよび情報

SQL Server 2005 の参考資料の入手

変更履歴

リリース 履歴

2007 年 9 月 15 日

新しい内容 :
  • @sync_type パラメータに対する値 none の指定が推奨されないことを示す注を追加しました。

2006 年 12 月 12 日

変更内容 :
  • 匿名サブスクリプションは推奨されていないという記述が誤りであったため削除。