共用方式為


sp_reinitmergesubscription (Transact-SQL)

適用於:SQL Server

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

Transact-SQL 語法慣例

語法

sp_reinitmergesubscription
    [ [ @publication = ] N'publication' ]
    [ , [ @subscriber = ] N'subscriber' ]
    [ , [ @subscriber_db = ] N'subscriber_db' ]
    [ , [ @upload_first = ] N'upload_first' ]
[ ; ]

引數

[ @publication = ] N'publication'

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

[ @subscriber = ] N'subscriber'

訂閱者的名稱。 @subscriber為 sysname,預設值為 all

[ @subscriber_db = ] N'subscriber_db'

訂閱者資料庫的名稱。 @subscriber_db為 sysname,預設值為 all

[ @upload_first = ] N'upload_first'

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

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

傳回碼值

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

備註

sp_reinitmergesubscription 用於合併式複寫。

sp_reinitmergesubscription 可以從發行者呼叫以重新初始化合併訂閱。 您也應該重新執行 快照集代理程式。

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

範例

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 @subscriptionDB AS sysname;
DECLARE @publication AS sysname;
SET @subscriptionDB = N'AdventureWorks2022Replica';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2022Replica]

-- Execute at the Publisher to reinitialize the push subscription. 
-- Pending changes at the Subscrber are lost.
EXEC sp_reinitmergesubscription 
    @subscriber = $(SubServer),
    @subscriber_db = @subscriptionDB,
    @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 @subscriptionDB AS sysname;
DECLARE @publication AS sysname;
SET @subscriptionDB = N'AdventureWorks2022Replica';
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2022Replica]

-- Execute at the Publisher to reinitialize the push subscription, 
-- and upload pending changes at the Subscriber. 
EXEC sp_reinitmergesubscription 
    @subscriber = $(SubServer),
    @subscriber_db = @subscriptionDB,
    @publication = @publication,
    @upload_first = N'true';
GO

-- Start the Merge Agent.

權限

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