복제 스크립트 업그레이드(복제 Transact-SQL 프로그래밍)

적용 대상:SQL ServerAzure SQL Managed Instance

Transact-SQL 스크립트 파일을 사용하여 복제본(replica)tion 토폴로지 프로그래밍 방식으로 구성할 수 있습니다. 자세한 내용은 복제 시스템 저장 프로시저 개념을 참조하세요.

Important

sysadmin 역할의 멤버가 실행하는 스크립트를 업그레이드할 필요는 없지만 이 항목에 설명된 대로 기존 스크립트를 수정하는 것이 좋습니다. 복제 에이전트 보안 모델 항목의 "에이전트에 필요한 권한" 섹션에 설명된 대로 각 복제본(replica)tion 에이전트에 대한 최소 권한이 있는 계정을 지정합니다.

복제본(replica) 에이전트 작업이 실행되는 Microsoft Windows 계정을 명시적으로 지정할 수 있도록 하여 사용 권한을 보다 효율적으로 제어할 수 있도록 하는 이러한 보안 개선 사항은 기존 스크립트의 다음 저장 프로시저에 영향을 줍니다.

SQL Server 2005(9.x)에 도입된 보안 모델에서 복제본(replica) 에이전트는 항상 제공된 자격 증명을 사용하여 Windows 인증을 사용하여 SQL Server의 로컬 인스턴스에 @job_name 연결합니다@job_password. 복제본(replica) 에이전트 작업을 실행할 때 사용되는 Windows 계정의 요구 사항에 대한 자세한 내용은 복제 에이전트 보안 모델을 참조하세요.

Important

가능한 경우 런타임 시 사용자에게 보안 자격 증명을 입력하라는 메시지가 표시됩니다. 스크립트 파일에 자격 증명을 저장하는 경우 파일 자체의 보안이 유지되는지 확인합니다.

스냅샷 또는 트랜잭션 게시를 구성하는 스크립트를 업그레이드하려면

  1. 기존 스크립트에서 sp_addpublication(Transact-SQL) 전에 게시 데이터베이스의 게시자에서 sp_addlogreader_agent(Transact-SQL)를 실행합니다. 로그 판독기 에이전트가 실행되는 @job_name Windows 자격 증명을 지정합니다.@job_password 에이전트가 게시자에 연결할 때 SQL Server 인증을 사용하는 경우 값 0 @publisher_security_mode 과 SQL Server 로그인 정보 @publisher_login@publisher_password도 지정해야 합니다. 그러면 게시 데이터베이스에 대한 로그 판독기 에이전트 작업이 만들어집니다.

    참고 항목

    이 단계는 트랜잭션 게시에만 해당하며 스냅샷 게시에는 필요하지 않습니다.

  2. (선택 사항) sp_addpublication 전에(Transact-SQL) 배포 데이터베이스의 배포자에서 sp_addqreader_agent(Transact-SQL)를 실행합니다. @job_name@job_password에 큐 판독기 에이전트 실행에 사용되는 Windows 자격 증명을 지정합니다. 이렇게 하면 배포자에 대한 큐 판독기 에이전트가 만들어집니다.

    참고 항목

    이 단계는 대기 중인 업데이트 구독자를 지원하는 트랜잭션 게시에만 필요합니다.

  3. (선택 사항) 새 복제본(replica)tion 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정하도록 sp_addpublication(Transact-SQL) 실행을 업데이트합니다.

  4. sp_addpublication(Transact-SQL)를 실행한 후 게시 데이터베이스의 게시자에서 sp_addpublication_스냅샷(Transact-SQL)를 실행합니다. 스냅샷 에이전트 실행되는 Windows 자격 증명 및 해당 자격 증명을 @job_name 지정 @publication 합니다@job_password. 에이전트가 게시자에 연결할 때 SQL Server 인증을 사용하는 경우 값 0 @publisher_security_mode 과 SQL Server 로그인 정보 @publisher_login@publisher_password도 지정해야 합니다. 이렇게 하면 게시에 대해 스냅샷 에이전트 작업이 만들어집니다.

  5. (선택 사항) 새 복제본(replica)tion 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정하도록 sp_addarticle(Transact-SQL) 실행을 업데이트합니다.

스냅샷 또는 트랜잭션 게시에 구독을 추가하는 스크립트를 업그레이드하려면

  1. 구독을 만드는 저장 프로시저를 실행한 후 구독을 동기화하는 배포 에이전트 작업을 만드는 저장 프로시저를 실행해야 합니다. 사용하는 저장 프로시저는 구독 유형에 따라 달라집니다.

    • 끌어오기 구독의 경우 sp_addpullsubscription_agent(Transact-SQL) 실행을 업데이트하여 구독자에서 배포 에이전트 실행되는 Windows 자격 증명을 @job_name@job_password제공합니다. 이 작업은 sp_addpullsubscription을 실행한 후에 수행합니다. 자세한 내용은 끌어오기 구독 만들기를 참조 하세요.

    • 밀어넣기 구독의 경우 게시자에서 sp_addpushsubscription_agent(Transact-SQL)를 실행합니다. @publication@subscriber_db배포자에서 배포 에이전트 실행되는 Windows 자격 증명 및 @job_password이 에이전트 작업에 대한 @job_name 일정을 지정@subscriber합니다. 자세한 내용은 Specify Synchronization Schedules을 참조하세요. 이 작업은 sp_addsubscription을 실행한 후에 수행됩니다. 자세한 내용은 밀어넣기 구독 만들기을 참조하세요.

병합 게시를 구성하는 스크립트를 업그레이드하려면

  1. (선택 사항) 기존 스크립트에서 새 복제본(replica)tion 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정하도록 sp_addmergepublication(Transact-SQL) 실행을 업데이트합니다.

  2. sp_addmergepublication(Transact-SQL) 후에 게시 데이터베이스의 게시자에서 sp_addpublication_스냅샷(Transact-SQL)를 실행합니다. 스냅샷 에이전트 실행되는 Windows 자격 증명 및 해당 자격 증명을 @job_name 지정 @publication 합니다@job_password. 에이전트가 게시자에 연결할 때 SQL Server 인증을 사용하는 경우 값 0 @publisher_security_mode 과 SQL Server 로그인 정보 @publisher_login@publisher_password도 지정해야 합니다. 이렇게 하면 게시에 대해 스냅샷 에이전트 작업이 만들어집니다.

  3. (선택 사항) 새 복제본(replica)tion 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정하도록 sp_addmergearticle(Transact-SQL) 실행을 업데이트합니다.

병합 게시에 구독을 추가하는 스크립트를 업그레이드하려면

  1. 구독을 만드는 저장 프로시저를 실행한 후 구독을 동기화할 병합 에이전트를 만드는 저장 프로시저를 실행합니다. 사용하는 저장 프로시저는 구독 유형에 따라 달라집니다.

    • 끌어오기 구독의 경우 sp_addmergepullsubscription_agent(Transact-SQL) 실행을 업데이트하여 구독자에서 병합 에이전트 실행되는 Windows 자격 증명을 @job_name@job_password제공합니다. 이 작업은 sp_addmergepullsubscription 실행한 후에 수행됩니다. 자세한 내용은 끌어오기 구독 만들기를 참조 하세요.

    • 밀어넣기 구독의 경우 게시자에서 sp_addmergepushsubscription_agent(Transact-SQL)를 실행합니다. 배포@publication@subscriber_db자에서 병합 에이전트 실행되는 Windows 자격 증명 및 @job_password이 에이전트 작업에 대한 @job_name 일정을 지정@subscriber합니다. 자세한 내용은 Specify Synchronization Schedules을 참조하세요. 이 작업은 sp_addmergesubscription 실행한 후에 수행됩니다. 자세한 내용은 밀어넣기 구독 만들기을 참조하세요.

예제

A. 트랜잭션 게시를 만드는 SQL Server 2000 스크립트

다음은 Product 테이블에 대한 트랜잭션 게시를 만드는 SQL Server 2000(8.x) 스크립트의 예입니다. 이 게시는 지연 업데이트를 장애 조치(failover)로 즉시 업데이트할 수 있습니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.

USE [Northwind]
GO

DECLARE @publication AS sysname
DECLARE @publicationDB AS sysname
DECLARE @article AS sysname
SET @publication = N'NwdProductTran'
SET @publicationDB = N'Northwind'
SET @article = N'Products'

-- Enable the replication database.
EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'publish', 
    @value = N'true'

-- Add the transactional publication.
EXEC sp_addpublication 
    @publication = @publication, 
    @sync_method = N'native', 
    @status = N'active', 
    @repl_freq = N'continuous', 
    @description = N'Transactional publication of Northwind.', 
    @allow_push = N'true', 
    @allow_pull = N'true', 
    @allow_sync_tran = N'true', 
    @autogen_sync_procs = N'true', 
    @allow_queued_tran = N'true'

-- Add a snapshot job.
EXEC sp_addpublication_snapshot 
    @publication = @publication

-- Add the transactional articles.
EXEC sp_addarticle 
    @publication = @publication, 
    @article = @article, 
    @source_owner = N'dbo', 
    @source_object = @article, 
    @destination_table = @article, 
    @type = N'logbased', 
    @schema_option = 0x00000000000080F3, 
    @ins_cmd = N'CALL sp_MSins_Products', 
    @del_cmd = N'XCALL sp_MSdel_Products', 
    @upd_cmd = N'XCALL sp_MSupd_Products', 
    @auto_identity_range = N'false'
GO

B. 트랜잭션 게시를 만드는 SQL Server 2005 이상 스크립트

다음은 SQL Server 2005(9.x) 이상 버전에서 성공적으로 실행되도록 트랜잭션 게시를 만드는 이전 스크립트를 업그레이드하는 예제입니다. 이 게시는 지연 업데이트를 장애 조치(failover)로 즉시 업데이트할 수 있습니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.

참고 항목

Windows 자격 증명은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- To avoid storing the login and password in the script file, the value 
-- is passed into SQLCMD as a scripting variable. 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 at the Distributor.
USE [distribution]

DECLARE @login AS sysname;
DECLARE @password AS sysname;
-- Specify the Windows account to run the Queue Reader Agent.
SET @login = $(Login); 
-- Pass the password at runtime.
SET @password = $(Password); 

-- Execute sp_addqreader_agent to create the Queue Reader Agent job. 
EXEC sp_addqreader_agent 
    @job_login = @login, 
    @job_password = @password;
GO

-- Execute at the Publisher.
USE [Northwind]
GO

DECLARE @publication AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @article AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdProductTran';
SET @publicationDB = N'Northwind';
SET @article = N'Products';
-- Specify the Windows account to run the Log Reader and Snapshot Agents.
SET @login = $(Login); 
-- Pass the password at runtime.
SET @password = $(Password); 

-- Enable the replication database.
EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'publish', 
    @value = N'true';

-- Execute sp_addlogreader_agent to create the agent job. 
EXEC sp_addlogreader_agent 
    @job_login = @login, 
    @job_password = @password, 
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;

-- Add the transactional publication.
EXEC sp_addpublication 
    @publication = @publication, 
    @sync_method = N'native', 
    @repl_freq = N'continuous', 
    @status = N'active',
    @description = N'Transactional publication of Northwind.', 
    @allow_push = N'true', 
    @allow_pull = N'true', 
    @allow_sync_tran = N'true', 
    @autogen_sync_procs = N'true', 
    @allow_queued_tran = N'true',
    @replicate_ddl = 1,
    @enabled_for_p2p = N'false';

-- Create a new snapshot job for the publication, using a default schedule.
EXEC sp_addpublication_snapshot 
    @publication = @publication, 
    @job_login = @login, 
    @job_password = @password,
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;

-- Add a transactional article.
EXEC sp_addarticle 
  @publication = @publication, 
  @article = @article, 
  @source_owner = N'dbo', 
  @source_object = @article, 
  @destination_table = @article, 
  @type = N'logbased', 
  @schema_option = 0x00000000000080F3, 
  @ins_cmd = N'CALL sp_MSins_Products', 
  @del_cmd = N'XCALL sp_MSdel_Products', 
  @upd_cmd = N'XCALL sp_MSupd_Products', 
  @auto_identity_range = N'false',
  @identityrangemanagementoption = N'manual',
  @fire_triggers_on_snapshot = N'false';
GO

C. 병합 게시를 만드는 SQL Server 2000 스크립트

다음은 Customers 테이블에 대한 병합 게시를 만드는 SQL Server 2000(8.x) 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.

-- Enable the replication database.
USE [Northwind]
GO

DECLARE @publicationDB AS sysname
DECLARE @publication AS sysname
DECLARE @article AS sysname
SET @publicationDB = N'Northwind' 
SET @publication = N'NwdCustomersMerge' 
SET @article = N'Customers' 

EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'merge publish', 
    @value = N'true'

-- Add the merge publication.
EXEC sp_addmergepublication 
    @publication = @publication, 
    @description = N'Merge publication of Northwind.', 
    @retention = 14, 
    @sync_mode = N'native', 
    @centralized_conflicts = N'true', 
    @dynamic_filters = N'false', 
    @keep_partition_changes = N'false'
 
EXEC sp_addpublication_snapshot 
    @publication = @publication

-- Add the merge articles.
EXEC sp_addmergearticle 
    @publication = @publication, 
    @article = @article, 
    @source_owner = N'dbo', 
    @source_object = @article, 
    @type = N'table', 
    @description = null, 
    @column_tracking = N'true', 
    @schema_option = 0x000000000000CFF1
 GO

D. 병합 게시를 만드는 SQL Server 2005 이상의 스크립트

다음은 SQL Server 2005(9.x) 이상 버전에서 성공적으로 실행되도록 업그레이드된 병합 게시를 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.

참고 항목

Windows 자격 증명은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- To avoid storing the login and password in the script file, the value 
-- is passed into SQLCMD as a scripting variable. 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".

-- Enabling the replication database
-- Enable the replication database.
USE [Northwind]
GO

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
DECLARE @article AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publicationDB = N'Northwind';
SET @publication = N'NwdCustomersMerge';
SET @article = N'Customers';
-- Specify the Windows account to run the Snapshot Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

EXEC sp_replicationdboption 
    @dbname = @publicationDB, 
    @optname = N'merge publish', 
    @value = N'true';

-- Add the merge publication.
EXEC sp_addmergepublication 
    @publication = @publication, 
    @description = N'Merge publication of Northwind.', 
    @retention = 14, 
    @sync_mode = N'native', 
    @dynamic_filters = N'false', 
    @keep_partition_changes = N'false',
    -- Only set to '90RTM' if all Subscribers are SQL Server 2005.
    @publication_compatibility_level = N'90RTM',
    @replicate_ddl = 1,
    @allow_subscriber_initiated_snapshot = N'true',
    @allow_web_synchronization = N'false',
    @allow_partition_realignment = N'true',
    @retention_period_unit = N'day',
    @automatic_reinitialization_policy = 0,
    @conflict_logging = N'both';
 
EXEC sp_addpublication_snapshot 
    @publication = @publication, 
    @job_login = @login,
    @job_password = @password;

-- Add the merge article.
EXEC sp_addmergearticle 
    @publication = @publication, 
    @article = @article, 
    @source_owner = N'dbo', 
    @source_object = @article, 
    @type = N'table', 
    @description = null, 
    @column_tracking = N'true', 
    @schema_option = 0x0000000000034FD1,
    @partition_options = 0,
    @subscriber_upload_options = 0,
    @identityrangemanagementoption = N'manual',
    @delete_tracking = N'true',
    @compensate_for_errors = N'false',
    @stream_blob_columns = N'true';
GO

E. 트랜잭션 게시에 대한 밀어넣기 구독을 만드는 SQL Server 2000 스크립트

다음은 트랜잭션 게시에 대한 밀어넣기 구독을 만드는 SQL Server 2000(8.x) 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.

DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'NwdProductTran' 
SET @subscriber = N'MYSUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
    @subscriber = @subscriber

-- Add a push subscription to a transactional publication.
USE [Northwind]
EXEC sp_addsubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @destination_db = @subscriptionDB, 
    @subscription_type = N'push'
GO

F. 트랜잭션 게시에 밀어넣기 구독을 만드는 SQL Server 2005 이상의 스크립트

다음은 SQL Server 2005(9.x) 이상 버전에 대해 성공적으로 실행되도록 업그레이드된 트랜잭션 게시에 대한 밀어넣기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.

참고 항목

Windows 자격 증명은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- 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 @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdProductTran'; 
SET @subscriber = $(Subscriber); 
SET @subscriptionDB = N'NorthwindReplica'; 
-- Specify the Windows account to run the Distribution Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

-- Add a push subscription to a transactional publication.
USE [Northwind]
EXEC sp_addsubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @destination_db = @subscriptionDB, 
    @subscription_type = N'push';

-- Add an agent job to synchronize the push subscription.
EXEC sp_addpushsubscription_agent 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @job_login = @login, 
    @job_password = @password;
GO

G. 병합 게시에 대한 밀어넣기 구독을 만드는 SQL Server 2000 스크립트

다음은 병합 게시에 대한 밀어넣기 구독을 만드는 SQL Server 2000(8.x) 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.

DECLARE @publication AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @subscriber = N'SUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
  @subscriber = @subscriber

-- Add a push subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'push',
  @subscriber_type = N'local',
  @sync_type = N'automatic'
GO

H. 병합 게시에 대한 밀어넣기 구독을 만드는 SQL Server 2005 이상 스크립트

다음은 SQL Server 2005(9.x) 이상 버전에서 성공적으로 실행되도록 업그레이드된 병합 게시에 대한 밀어넣기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.

참고 항목

Windows 자격 증명은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- 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 @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdCustomersMerge'; 
SET @subscriber = $(Subscriber); 
SET @subscriptionDB = N'NorthwindReplica'; 
-- Specify the Windows account to run the Merge Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

-- Add a push subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @subscription_type = N'push';

-- Add an agent job to synchronize the push subscription.
EXEC sp_addmergepushsubscription_agent 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @job_login = @login, 
    @job_password = @password;
GO

9\. 트랜잭션 게시에 대한 끌어오기 구독을 만드는 SQL Server 2000 스크립트

다음은 트랜잭션 게시에 대한 끌어오기 구독을 만드는 SQL Server 2000(8.x) 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.

DECLARE @publication AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @subscriber = N'SUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
  @subscriber = @subscriber

-- Add a push subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'push',
  @subscriber_type = N'local',
  @sync_type = N'automatic'
GO

J. 트랜잭션 게시에 대한 끌어오기 구독을 만드는 SQL Server 2005 이상 스크립트

다음은 SQL Server 2005(9.x) 이상 버전에서 성공적으로 실행되도록 업그레이드된 트랜잭션 게시에 대한 끌어오기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.

참고 항목

Windows 자격 증명은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- 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 at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdProductTran'; 
SET @publisher = $(Publisher); 
SET @publicationDB = N'Northwind'; 
-- Specify the Windows account to run the Distribution Agent.
SET @login = $(Login); 
-- Supply the password at runtime.
SET @password = $(Password); 

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

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

-- Execute at the Publisher.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'NwdProductTran'; 
SET @subscriber = $(Subscriber); 
SET @subscriptionDB = N'NorthwindReplica'; 

-- Add a pull subscription to a transactional publication.
USE [Northwind]
EXEC sp_addsubscription 
    @publication = @publication, 
    @subscriber = @subscriber, 
    @destination_db = @subscriptionDB, 
    @subscription_type = N'pull';
GO

11. 병합 게시에 대한 끌어오기 구독을 만드는 SQL Server 2000 스크립트

다음은 병합 게시에 대한 끌어오기 구독을 만드는 SQL Server 2000(8.x) 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.

-- Execute at the Subscriber
DECLARE @publication AS sysname
DECLARE @publisher AS sysname
DECLARE @publicationDB AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @publisher = N'PUBSERVER' 
SET @publicationDB = N'Northwind' 
SET @subscriber = N'SUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica'

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [NorthwindReplica]
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, 
    @subscriber = @subscriber, 
    @subscriber_db = @subscriptionDB, 
    @distributor = @publisher
GO

-- Execute at the Publisher.
DECLARE @publication AS sysname
DECLARE @subscriber AS sysname
DECLARE @subscriptionDB AS sysname
SET @publication = N'NwdCustomersMerge' 
SET @subscriber = N'MYSUBSERVER' 
SET @subscriptionDB = N'NorthwindReplica' 

-- Add a Subscriber, using the defaults.
USE [master]
EXEC sp_addsubscriber 
  @subscriber = @subscriber

-- Add a pull subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'pull',
  @subscriber_type = N'local',
  @sync_type = N'automatic'
GO

12. 병합 게시에 대한 끌어오기 구독을 만드는 SQL Server 2005 이상 스크립트

다음은 SQL Server 2005(9.x) 이상 버전에서 성공적으로 실행되도록 업그레이드된 병합 게시에 대한 끌어오기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.

참고 항목

Windows 자격 증명은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- 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 at the Subscriber
DECLARE @publication  AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publication = N'NwdCustomersMerge'; 
SET @publisher = $(Publisher); 
SET @publicationDB = N'Northwind'; 
-- Specify the Windows account to run the Merge Agent.
SET @login = $(Login); 
-- Pass the password at runtime.
SET @password = $(Password); 

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [NorthwindReplica]
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;
GO

-- Execute at the Publisher.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'NwdCustomersMerge';
SET @subscriber = $(Subscriber);
SET @subscriptionDB = N'NorthwindReplica';

-- Add a pull subscription to a merge publication.
USE [Northwind]
EXEC sp_addmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB, 
  @subscription_type = N'pull',
  @subscriber_type = N'local',
  @sync_type = N'automatic';
GO

참고 항목

게시 만들기
밀어넣기 구독 만들기
끌어오기 구독 만들기
복제 보안 설정 보기 및 수정
MSSQL_ENG021797
MSSQL_ENG021798
Replication System Stored Procedures Concepts
복제된 데이터베이스 업그레이드