sp_reinitmergesubscription (Transact-SQL)
适用范围:SQL Server
将合并订阅标记为在下次运行合并代理时重新初始化。 此存储过程可在发布服务器的任意发布数据库中执行。
语法
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.
权限
只有 sysadmin 固定服务器角色的成员或db_owner固定数据库角色的成员才能执行sp_reinitmergesubscription
。