sp_addpullsubscription (Transact-SQL)

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

將提取訂閱新增至快照式或交易式發行集。 這個預存程式會在要建立提取訂閱之資料庫的訂閱者端執行。

Transact-SQL 語法慣例

語法

sp_addpullsubscription
    [ @publisher = ] N'publisher'
    [ , [ @publisher_db = ] N'publisher_db' ]
    , [ @publication = ] N'publication'
    [ , [ @independent_agent = ] N'independent_agent' ]
    [ , [ @subscription_type = ] N'subscription_type' ]
    [ , [ @description = ] N'description' ]
    [ , [ @update_mode = ] N'update_mode' ]
    [ , [ @immediate_sync = ] immediate_sync ]
[ ; ]

引數

[ @publisher = ] N'publisher'

發行者的名稱。 @publisher為 sysname,沒有預設值。

注意

伺服器名稱可以指定為 <Hostname>,<PortNumber>。 使用自定義埠在Linux或 Windows 上部署 SQL Server,並停用瀏覽器服務時,請指定連線的埠號碼。 遠端散發者的自定義埠號碼使用適用於 SQL Server 2019 (15.x) 和更新版本。

[ @publisher_db = ] N'publisher_db'

發行者資料庫的名稱。 @publisher_db為 sysname,預設值為 NULLOracle 發行者會忽略@publisher_db

[ @publication = ] N'publication'

發行集的名稱。 @publication為 sysname,沒有預設值。

[ @independent_agent = ] N'independent_agent'

指定此發行集是否有獨立 散發代理程式。 @independent_agent為 nvarchar(5),預設值為 true

  • 如果true為 ,則此出版物有獨立 散發代理程式。
  • 如果false為 ,則每個 Publisher 資料庫/訂閱者資料庫組都有一個 散發代理程式。

@independent_agent是發行集的屬性,而且必須與發行者具有相同的值。

[ @subscription_type = ] N'subscription_type'

訂用帳戶的類型。 @subscription_type為 nvarchar(9),預設值為 anonymous。 除非您想要在發行者端註冊訂閱,否則您必須為 @subscription_type 指定的值pull。 在此情況下,您必須指定的值 anonymous。 在訂用帳戶設定期間,您無法建立與發行者之 SQL Server 連線的情況,這是必要的。

[ @description = ] N'description'

發行集的描述。 @description為 nvarchar(100),預設值為 NULL

[ @update_mode = ] N'update_mode'

更新的類型。 @update_mode為 nvarchar(30),而且可以是下列其中一個值。

Description
read only (預設值) 訂閱是唯讀的。 訂閱者端的任何變更都不會傳回給發行者。 在訂閱者端未進行更新時,應該使用。
synctran 啟用立即更新訂閱的支援。
queued tran 啟用佇列更新的訂用帳戶。 您可以在訂閱者端進行數據修改、儲存在佇列中,然後傳播至發行者。
failover 啟用訂閱,以佇列更新作為故障轉移進行立即更新。 您可以在訂閱者端進行數據修改,並立即傳播至發行者。 如果發行者和訂閱者未連線,則在訂閱者和發行者重新連線之前,可以在佇列中儲存在訂閱者端進行的數據修改。
queued failover 注意: Oracle 發行者不支援。

讓訂用帳戶成為佇列更新訂閱,並能夠變更為立即更新模式。 您可以在訂閱者端進行數據修改,並儲存在佇列中,直到訂閱者與發行者之間建立連接為止。 建立連續連線時,更新模式可以變更為立即更新。

[ @immediate_sync = ] immediate_sync

指定每次執行 快照集代理程式 時,都會建立或重新建立同步處理檔案。 @immediate_sync為 bit,預設值1為 ,且必須設定為與 sp_addpublication (Transact-SQL)@immediate_sync相同的值@immediate_sync是發行集的屬性,而且必須與發行者具有相同的值。

傳回碼值

0 (成功)或 1 (失敗)。

備註

sp_addpullsubscription 用於快照式複寫和事務複製。

重要

針對佇列更新訂閱,請使用 SQL Server 驗證來連線到訂閱者,並為每個訂閱者的連接指定不同的帳戶。 建立支援佇列更新的提取訂閱時,複寫一律會將聯機設定為使用 Windows 驗證(針對提取訂閱,復寫無法在使用 SQL Server 驗證所需的訂閱者端存取元數據)。 在此情況下,您應該執行 sp_changesubscription ,以在設定訂用帳戶之後,將聯機變更為使用 SQL Server 驗證。

如果MSreplication_subscriptions (Transact-SQL) 數據表不存在於訂閱者端,sp_addpullsubscription請加以建立。 它也會將數據列新增至 MSreplication_subscriptions (Transact-SQL) 數據表。 針對提取訂閱,應該先在發行者端呼叫 sp_addsubscription (Transact-SQL)。

範例

-- 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;
SET @publication = N'AdvWorksProductTran';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2022';

-- At the subscription database, create a pull subscription 
-- to a transactional publication.
USE [AdventureWorks2022Replica]
EXEC sp_addpullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription.
EXEC sp_addpullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication, 
  @distributor = @publisher, 
  @job_login = $(Login), 
  @job_password = $(Password);
GO

權限

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