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'
    這是發行集的名稱。publicationsysname,沒有預設值。
  • [ @publisher=] 'publisher'
    這是發行者的名稱。Publishersysname,預設值是本機伺服器名稱。發行者必須是有效伺服器。
  • [ @publisher_db =] 'publisher_db'
    這是發行者資料庫的名稱。publisher_dbsysname,預設值是 NULL。
  • [ @subscriber_type=] 'subscriber_type'
    這是訂閱者的類型。subscriber_typenvarchar(15),它可以是 globallocalanonymous。在 SQL Server 2005 中,本機訂閱稱為客訂閱,全域訂閱稱為主訂閱。如需詳細資訊,請參閱<合併式複寫如何偵測並解決衝突>中的<訂閱類型>一節。如果您想要建立訂閱但不要在發行者端註冊訂閱,則需要 anonymous 的值。對於 Web 同步處理之類的案例,這是必要的,因為在這種案例中,您不能在設定訂閱組態時建立訂閱者的 SQL Server 連接。
  • [ @subscription_priority=] subscription_priority
    這是訂閱優先權。subscription_priorityreal,預設值是 NULL。如果是本機和匿名訂閱,優先權就是 0.0。在偵測到衝突時,預設解析程式會利用優先權挑選贏的一方。如果是全域訂閱者,訂閱優先權必須小於 100,也就是發行者的優先權。
  • [ @sync_type=] 'sync_type'
    這是訂閱同步處理類型。sync_typenvarchar(15),預設值是 automatic。它可以是 automaticnone。如果是 automatic,便先將發行資料表的結構描述和初始資料傳送給訂閱者。如果是 none,便假設訂閱者已有發行資料表的結構描述和初始資料。一律會傳送系統資料表和資料。

    ms189456.note(zh-tw,SQL.90).gif附註:
    我們不建議指定 none 的值。如需詳細資訊,請參閱<不使用快照集初始化合併訂閱>。
  • [ @description=] 'description'
    這是這項提取訂閱的簡要描述。descriptionnvarchar(255),預設值是 NULL。複寫監視器會在易記名稱資料行中顯示這個值,這個資料行可用來排序所監視之發行集的訂閱。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_addmergepullsubscription 用於合併式複寫中。

如果利用 SQL Server Agent 來同步處理訂閱,您必須在訂閱者端執行 sp_addmergepullsubscription_agent 預存程序來建立代理程式和作業,以便與發行集同步處理。

權限

只有系統管理員 (sysadmin) 固定伺服器角色或 db_owner 固定資料庫角色的成員,才能夠執行 sp_addmergepullsubscription

範例

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

變更的內容:
  • 移除錯誤陳述匿名訂閱已被取代的內容。