sp_addmergepullsubscription (Transact-SQL)

適用於:SQL ServerAzure SQL 受控執行個體

將提取訂閱新增至合併式發行集。 這個預存程式會在訂閱資料庫的訂閱者端執行。

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),預設值local為 ,而且可以是 、 localanonymousglobal其中一個。 在 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。 可以是 automaticnone。 如果 automatic為 ,則發行數據表的架構和初始數據會先傳送至訂閱者。 如果 none為 ,則假設訂閱者已經有已發行數據表的架構和初始數據。 系統數據表和數據一律會傳送。

我們建議指定的值 automatic

[ @description = ] N'description'

此提取訂閱的簡短描述。 @description為 nvarchar(255),預設值為 NULL。 這個值是由數據行中的 Friendly Name 復寫監視器所顯示,可用來排序受監視發行集的訂閱。

傳回碼值

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

權限

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