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),它可以是 globallocalanonymous。 在 SQL Server 2005 和更新版本中,本機訂閱稱為客訂閱,而全域訂閱稱為主訂閱。

  • [ @subscription_priority=] subscription_priority
    這是訂閱優先權。 subscription_priority是 real,預設值是 NULL。 如果是本機和匿名訂閱,優先權就是 0.0。 在偵測到衝突時,預設解析程式會利用優先權挑選贏的一方。 如果是全域訂閱者,訂閱優先權必須小於 100,也就是發行者的優先權。

  • [ @sync_type=] 'sync_type'
    這是訂閱同步處理類型。 sync_type 是 nvarchar(15),預設值是 automatic。 它可以是 automaticnone。 如果是 automatic,便先將發行資料表的結構描述和初始資料傳送給訂閱者。 如果是 none,便假設訂閱者已有發行資料表的結構描述和初始資料。 一律會傳送系統資料表和資料。

    [!附註]

    我們不建議您指定 none 值。

  • [ @description=] 'description'
    這是這項提取訂閱的簡要描述。 description是 nvarchar(255),預設值是 NULL。 複寫監視器會在易記名稱資料行中顯示這個值,這個資料行可用來排序所監視之發行集的訂閱。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_addmergepullsubscription 用於合併式複寫中。

如果利用 SQL Server Agent 來同步處理訂閱,您必須在訂閱者端執行 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'AdventureWorks2012';
SET @hostname = N'adventure-works\david8';

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

請參閱

參考

sp_addmergepullsubscription_agent (Transact-SQL)

sp_changemergepullsubscription (Transact-SQL)

sp_dropmergepullsubscription (Transact-SQL)

sp_helpmergepullsubscription (Transact-SQL)

sp_helpsubscription_properties (Transact-SQL)

概念

建立提取訂閱

訂閱發行集