共用方式為


sp_reinitmergepullsubscription (Transact-SQL)

適用於:SQL Server

標記合併提取訂閱,以便下次執行 合併代理程式 時重新初始化。 這個預存程式會在訂閱資料庫的訂閱者端執行。

Transact-SQL 語法慣例

語法

sp_reinitmergepullsubscription
    [ [ @publisher = ] N'publisher' ]
    [ , [ @publisher_db = ] N'publisher_db' ]
    [ , [ @publication = ] N'publication' ]
    [ , [ @upload_first = ] N'upload_first' ]
[ ; ]

引數

[ @publisher = ] N'publisher'

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

[ @publisher_db = ] N'publisher_db'

發行者資料庫的名稱。 @publisher_db為 sysname,預設值為 all

[ @publication = ] N'publication'

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

[ @upload_first = ] N'upload_first'

指定在重新初始化訂閱之前,訂閱者端的變更是否上傳。 @upload_first為 nvarchar(5),預設值為 false

  • 如果 true為 ,則會在重新初始化訂閱之前上傳變更。
  • 如果 false為 ,則不會上傳變更。

傳回碼值

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

備註

sp_reinitmergepullsubscription 用於合併式複寫。

如果您新增、卸除或變更參數化篩選,則訂閱者端的擱置變更無法在重新初始化期間上傳至發行者。 如果您要上傳暫止變更,請在變更篩選之前,同步處理所有訂閱。

範例

A. 重新初始化提取訂閱,並遺失擱置中的變更

-- 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".

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
SET @publicationDB = N'AdventureWorks2022';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2022Replica]

-- Execute at the Subscriber to reinitialize the pull subscription. 
-- Pending changes at the Subscrber are lost.
EXEC sp_reinitmergepullsubscription 
    @publisher = $(PubServer),
    @publisher_db = @publicationDB,
    @publication = @publication,
    @upload_first = N'false';
GO

-- Start the Merge Agent.

B. 重新初始化提取訂閱並上傳擱置中的變更

-- 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".

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
SET @publicationDB = N'AdventureWorks2022';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2022Replica]

-- Execute at the Subscriber to reinitialize the pull subscription, 
-- and upload pending changes at the Subscriber. 
EXEC sp_reinitmergepullsubscription 
    @publisher = $(PubServer),
    @publisher_db = @publicationDB,
    @publication = @publication,
    @upload_first = N'true';
GO

-- Start the Merge Agent.

權限

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