sp_addmergepullsubscription(Transact-SQL)

적용 대상:SQL ServerAzure SQL Managed Instance

병합 게시에 끌어오기 구독을 추가합니다. 이 저장 프로시저는 구독 데이터베이스의 구독자에서 실행됩니다.

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 기본값localnvarchar(15)이며 , local또는 anonymous중 하나global일 수 있습니다. SQL Server 2005(9.x) 이상 버전에서는 로컬 구독을 클라이언트 구독이라고 하며 전역 구독을 서버 구독이라고 합니다.

[ @subscription_priority = ] subscription_priority

구독 우선 순위입니다. @subscription_priority 기본값NULL실제입니다. 로컬 및 익명 구독의 경우 우선 순위는 .입니다 0.0. 우선 순위는 충돌이 감지될 때 기본 해결 프로그램에서 승자를 선택하는 데 사용됩니다. 글로벌 구독자의 경우 구독 우선 순위는 게시자의 우선 순위인 구독 우선 순위보다 100작아야 합니다.

[ @sync_type = ] N'sync_type'

구독 동기화 유형입니다. @sync_type 기본값automatic인 nvarchar(15)입니다. automatic 또는 none일 수 있습니다. 이 경우 automatic게시된 테이블의 스키마 및 초기 데이터가 먼저 구독자에게 전송됩니다. 구독 none자에 게시된 테이블에 대한 스키마 및 초기 데이터가 이미 있는 것으로 간주됩니다. 시스템 테이블 및 데이터는 항상 전송됩니다.

의 값을 automatic지정하는 것이 좋습니다.

[ @description = ] N'description'

이 끌어오기 구독에 대한 간략한 설명입니다. @description 기본값NULL인 nvarchar(255)입니다. 이 값은 모니터링되는 게시에 대한 구독을 Friendly Name 정렬하는 데 사용할 수 있는 열의 복제 모니터에 의해 표시됩니다.

반환 코드 값

0 (성공) 또는 1 (실패).

설명

sp_addmergepullsubscription는 병합 복제본(replica)에 사용됩니다.

SQL Server 에이전트 사용하여 구독을 동기화하는 경우 구독자에서 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

사용 권한

sysadmin 고정 서버 역할 또는 db_owner 고정 데이터베이스 역할의 멤버만 실행할 sp_addmergepullsubscription수 있습니다.