Transact-SQL 스크립트 파일을 사용하여 프로그래밍 방식으로 복제 토폴로지 구성을 수행할 수 있습니다. 자세한 내용은 복제 시스템 저장 프로시저 개념을 참조하세요.
중요합니다
역할 멤버 sysadmin 가 실행하는 스크립트를 업그레이드할 필요는 없지만 이 항목에 설명된 대로 기존 스크립트를 수정하는 것이 좋습니다.
복제 에이전트 보안 모델 항목의 "에이전트에 필요한 권한" 섹션에 설명된 대로 각 복제 에이전트에 대한 최소 권한이 있는 계정을 지정합니다.
복제 에이전트 작업이 실행되는 Microsoft Windows 계정을 명시적으로 지정할 수 있도록 하여 사용 권한을 보다 효율적으로 제어할 수 있도록 하는 이러한 보안 개선 사항은 기존 스크립트의 다음 저장 프로시저에 영향을 줍니다.
sp_addpublication_snapshot:
이제 sp_addpublication_snapshot(Transact-SQL)를 실행할 때 @job_login과 @job_password을 Windows 자격 증명으로 제공하여 배포자에서 스냅샷 에이전트가 실행되는 작업을 만들어야 합니다.
sp_addpushsubscription_agent:
이제 sp_addpushsubscription_agent(Transact-SQL) 를 실행하여 작업을 명시적으로 추가하고 배포자에서 배포 에이전트 작업이 실행되는 Windows 자격 증명(@job_login 및 @job_password)을 제공해야 합니다. SQL Server 2005 이전 버전의 SQL Server에서는 밀어넣기 구독을 만들 때 자동으로 수행되었습니다.
sp_addmergepushsubscription_agent:
이제 sp_addmergepushsubscription_agent(Transact-SQL) 를 실행하여 작업을 명시적으로 추가하고 병합 에이전트 작업이 배포자에서 실행되는 Windows 자격 증명(@job_login 및 @job_password)을 제공해야 합니다. SQL Server 2005 이전 버전의 SQL Server에서는 밀어넣기 구독을 만들 때 자동으로 수행되었습니다.
sp_addpullsubscription_agent:
이제 sp_addpullsubscription_agent(Transact-SQL)를 실행할 때 @job_login 및 @job_password와 같은 Windows 자격 증명을 제공하여 구독자에서 배포 에이전트가 실행되는 작업을 만들어야 합니다.
sp_addmergepullsubscription_agent:
이제 Windows 자격 증명을 @job_login 및 @job_password로 제공하여 sp_addmergepullsubscription_agent(Transact-SQL)를 실행할 때 구독자에서 병합 에이전트가 실행되는 작업을 생성해야 합니다.
sp_addlogreader_agent:
이제 sp_addlogreader_agent(Transact-SQL) 를 실행하여 작업을 수동으로 추가하고 배포자에서 로그 판독기 에이전트가 실행되는 Windows 자격 증명을 제공해야 합니다. SQL Server 2005 이전 버전의 SQL Server에서는 트랜잭션 게시를 만들 때 자동으로 수행됩니다.
sp_addqreader_agent:
이제 sp_addqreader_agent(Transact-SQL) 를 실행하여 작업을 수동으로 추가하고 배포자에서 큐 판독기 에이전트가 실행되는 Windows 자격 증명을 제공해야 합니다. SQL Server 2005 이전 버전의 SQL Server에서는 지연 업데이트를 지원하는 트랜잭션 게시가 만들어지면 자동으로 수행됩니다.
SQL Server 2005에 도입된 보안 모델에서 복제 에이전트는 항상 @job_name 및 @job_password 제공된 자격 증명을 사용하여 Windows 인증을 사용하여 SQL Server의 로컬 인스턴스에 연결합니다. 복제 에이전트 작업을 실행할 때 사용되는 Windows 계정의 요구 사항에 대한 자세한 내용은 복제 에이전트 보안 모델을 참조하세요.
중요합니다
가능한 경우 런타임 시 사용자에게 보안 자격 증명을 입력하라는 메시지가 표시됩니다. 스크립트 파일에 자격 증명을 저장하는 경우 파일 자체의 보안이 유지되는지 확인합니다.
스냅샷 또는 트랜잭션 게시를 구성하는 스크립트를 업그레이드하려면
기존 스크립트에서 sp_addpublication(Transact-SQL)전에 게시 데이터베이스의 게시자에서 sp_addlogreader_agent(Transact-SQL) 를 실행합니다. @job_name 및@job_password 대해 로그 판독기 에이전트가 실행되는 Windows 자격 증명을 지정합니다. 에이전트가 게시자에 연결할 때 SQL Server 인증을 사용하는 경우 0의 값을 @publisher_security_mode에 지정하고, SQL Server 로그인 정보로서 @publisher_login과 @publisher_password을 지정해야 합니다. 그러면 게시 데이터베이스에 대한 로그 판독기 에이전트 작업이 만들어집니다.
비고
이 단계는 트랜잭션 게시에만 적용되며 스냅샷 게시에는 필요하지 않습니다.
(선택 사항) sp_addpublication(Transact-SQL)전에 배포 데이터베이스의 배포자에서 sp_addqreader_agent(Transact-SQL) 를 실행합니다. @job_name 및 @job_password에 대해 각각 큐 판독기 에이전트가 실행되는 Windows 자격 증명을 지정합니다. 그러면 배포자에 대한 큐 판독기 에이전트 작업이 만들어집니다.
비고
이 단계는 대기 중인 업데이트 구독자를 지원하는 트랜잭션 게시에만 필요합니다.
(선택 사항) sp_addpublication(Transact-SQL) 의 실행을 업데이트하여 새 복제 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정합니다.
sp_addpublication(Transact-SQL)를 수행한 후 게시 데이터베이스의 게시자에서 sp_addpublication_snapshot(Transact-SQL)를 실행합니다. @publication 및 Windows 자격 증명을 지정하십시오. @job_name 및 @job_password에 대해 스냅샷 에이전트가 실행됩니다. 에이전트가 게시자에 연결할 때 SQL Server 인증을 사용하는 경우, @publisher_security_mode에 대해 값 0을 지정하고, SQL Server 로그인 정보 @publisher_login과 @publisher_password을 함께 명시해야 합니다. 그러면 게시에 대한 스냅샷 에이전트 작업이 만들어집니다.
(선택 사항) sp_addarticle(Transact-SQL) 의 실행을 업데이트하여 새 복제 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정합니다.
스냅샷 또는 트랜잭션 게시에 구독을 추가하는 스크립트를 업그레이드하려면
구독을 만드는 저장 프로시저를 실행한 후 배포 에이전트 작업을 만들어 구독을 동기화하는 저장 프로시저를 실행해야 합니다. 사용하는 저장 프로시저는 구독 유형에 따라 달라집니다.
끌어오기 구독의 경우, 구독자에서 배포 에이전트가 작동하는 데 사용되는 Windows 자격 증명을 제공하기 위해 sp_addpullsubscription_agent(Transact-SQL)의 실행을 업데이트하여 @job_name 및 @job_password를 설정합니다. 이 작업은 sp_addpullsubscription 실행한 후에 수행됩니다. 자세한 내용은 끌어오기 구독 만들기를 참조하세요.
푸시 구독의 경우 게시자에서 sp_addpushsubscription_agent(Transact-SQL)를 실행합니다. @subscriber, @subscriber_db, @publication 및 Windows 자격 증명을 지정하여 배포자가 @job_name 및 @job_password의 배포 에이전트가 실행되도록 하고, 이 에이전트 작업에 대한 일정을 설정합니다. 자세한 내용은 동기화 일정 지정을 참조하세요. 이 작업은 sp_addsubscription 실행한 후에 수행됩니다. 자세한 내용은 밀어넣기 구독 만들기를 참조하세요.
병합 게시를 구성하는 스크립트를 업그레이드하려면
(선택 사항) 기존 스크립트에서 sp_addmergepublication(Transact-SQL) 의 실행을 업데이트하여 새 복제 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정합니다.
sp_addmergepublication(Transact-SQL)를 수행한 후 게시 데이터베이스의 게시자에서 sp_addpublication_snapshot(Transact-SQL)를 실행합니다. 스냅샷 에이전트가 실행되는 @publication 및 Windows 자격 증명을 @job_name와 @job_password에 대해 지정합니다. 에이전트가 게시자에 연결할 때 SQL Server 인증을 사용하는 경우, @publisher_security_mode 값에 대한 0과 @publisher_login 및 @publisher_password에 대한 SQL Server 로그인 정보를 꼭 지정해야 합니다. 게시물에 대한 스냅샷 에이전트 작업이 생성됩니다.
(선택 사항) sp_addmergearticle(Transact-SQL) 의 실행을 업데이트하여 새 복제 기능을 구현하는 매개 변수에 대한 기본값이 아닌 값을 설정합니다.
병합 게시에 구독을 추가하는 스크립트를 업그레이드하려면
구독을 만드는 저장 프로시저를 실행한 후 병합 에이전트 작업을 만들어 구독을 동기화하는 저장 프로시저를 실행해야 합니다. 사용하는 저장 프로시저는 구독 유형에 따라 달라집니다.
끌어오기 구독의 경우 sp_addmergepullsubscription_agent(Transact-SQL)의 실행을 업데이트하여 병합 에이전트가 @job_name 및 @job_password 구독자에서 실행되는 Windows 자격 증명을 제공합니다. 이 작업은 sp_addmergepullsubscription 실행한 후에 수행됩니다. 자세한 내용은 끌어오기 구독 만들기를 참조하세요.
푸시 구독의 경우 게시자에서 sp_addmergepushsubscription_agent(Transact-SQL)를 실행합니다. @subscriber, @subscriber_db, @publication, 배포자에서 병합 에이전트가 @job_name 및 @job_password 대해 실행되는 Windows 자격 증명 및 이 에이전트 작업에 대한 일정을 지정합니다. 자세한 내용은 동기화 일정 지정을 참조하세요. 이 작업은 sp_addmergesubscription 실행한 후에 수행됩니다. 자세한 내용은 밀어넣기 구독 만들기를 참조하세요.
예시
다음은 Product 테이블에 대한 트랜잭션 게시를 만드는 SQL Server 2000 스크립트의 예입니다. 이 문서는 대기 중인 업데이트를 장애 조치(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
예시
다음은 SQL Server 2005 이상 버전에서 성공적으로 실행되도록 트랜잭션 게시를 만드는 이전 스크립트를 업그레이드하는 예제입니다. 이 출판물은 장애 조치를 위해 즉시 업데이트를 지원하며 대기 중인 업데이트를 함께 처리합니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.
비고
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
예시
다음은 Customers 테이블에 대한 병합 게시를 만드는 SQL Server 2000 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.
-- 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
예시
다음은 SQL Server 2005 이상 버전에서 성공적으로 실행되도록 업그레이드된 병합 게시를 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.
비고
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
예시
다음은 트랜잭션 게시에 대한 푸시 구독을 만드는 SQL 서버 2000 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.
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
예시
다음은 SQL Server 2005 이상 버전에서 성공적으로 실행되도록 업그레이드된 트랜잭션 게시에 대한 밀어넣기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.
비고
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
예시
다음은 병합 게시물에 대한 푸시 구독을 생성하는 SQL Server 2000 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.
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
예시
다음은 SQL Server 2005 이상 버전에서 성공적으로 실행되도록 업그레이드된 병합 게시에 대한 밀어넣기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.
비고
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
예시
다음은 트랜잭션 게시에 대한 끌어오기 구독을 만드는 SQL Server 2000 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.
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
예시
다음은 SQL Server 2005 이상 버전에서 성공적으로 실행되도록 업그레이드된 트랜잭션 게시에 대한 끌어오기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.
비고
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
예시
다음은 병합 게시에 대한 끌어오기 구독을 만드는 SQL Server 2000 스크립트의 예입니다. 가독성을 위해 기본 매개 변수가 제거되었습니다.
-- 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
예시
다음은 SQL Server 2005 이상 버전에서 성공적으로 실행되도록 업그레이드된 병합 게시에 대한 끌어오기 구독을 만드는 이전 스크립트의 예입니다. 새 매개 변수의 기본값이 명시적으로 선언되었습니다.
비고
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
복제 시스템 저장 프로시저 개념
복제된 데이터베이스 업그레이드