Aracılığıyla paylaş


Yükseltme çoğaltma Scripts (çoğaltma Transact-sql programlama)

Transact-SQLkomut dosyaları, program kullanarak bir çoğaltma topolojisi yapılandırmak için kullanılabilir. Daha fazla bilgi için, bkz. Yineleme sistem saklı yordamlar kavramları.

Güvenlik notuGüvenlik Notu

Üyeleri tarafından çalıştırılan komut dosyalarının yükseltmek için gerekli değildir, ancak sysadminrolü, bu konuda açıklandığı gibi varolan komut dosyasını değiştirmek tavsiye ediyoruz. Her çoğaltma aracısı "izinleri gerekli tarafından ajanları" açıklandığı için minimum izinleri olan bir hesap belirtin Konu kısmına Çoğaltma aracısı güvenlik modeli.

Açıkça belirtmek vererek izinleri üzerinde daha fazla kontrol sağlayan bu güvenlik geliştirmeleri Microsoftaltında hangi çoğaltma aracısı işleri yürütülür, Windows hesaplarını etkileyen aşağıdaki saklı yordamları varolan komut:

  • sp_addpublication_snapshot:

    Şimdi Windows kimlik bilgileri olarak sağlamanız @ job_login ve @ job_password yürütürken sp_addpublication_snapshot (Transact-sql)Snapshot Aracısı çalıştığı Dağıtıcı iş oluşturmak için.

  • sp_addpushsubscription_agent:

    Şimdi bağlamını belirtir sp_addpushsubscription_agent (Transact-sql)açıkça bir iş eklemek ve Windows kimlik bilgilerini sağlamanız (@ job_login ve @ job_password) Dağıtım Aracısı iş dağıtımcı çalıştığı altında. Sürümlerinde SQL Serverönce SQL Server 2005, itme abonelik oluşturduğunuzda bu otomatik olarak yapıldı.

  • sp_addmergepushsubscription_agent:

    Şimdi bağlamını belirtir sp_addmergepushsubscription_agent (Transact-sql)açıkça bir iş eklemek ve Windows kimlik bilgilerini sağlamanız (@ job_login ve @ job_password) altında Birleştirme Aracısı iş dağıtımcı çalıştığı. Sürümlerinde SQL Serverönce SQL Server 2005, itme abonelik oluşturduğunuzda bu otomatik olarak yapıldı.

  • sp_addpullsubscription_agent:

    Şimdi Windows kimlik bilgileri olarak sağlamanız @ job_login ve @ job_password yürütürken yürütme eşdeğerdirsp_addpullsubscription_agent (Transact-sql)Dağıtım aracı çalıştığı altında abone adresindeki iş oluşturmak için.

  • sp_addmergepullsubscription_agent:

    Şimdi Windows kimlik bilgileri olarak sağlamanız @ job_login ve @ job_password yürütürken sp_addmergepullsubscription_agent (Transact-sql)Birleştirme Aracısı çalıştığı abone adresindeki iş oluşturmak için.

  • sp_addlogreader_agent:

    Şimdi bağlamını belirtir sp_addlogreader_agent (Transact-sql)el işi eklemek ve günlük Okuma Aracısı çalıştığı at dağıtımcı Windows kimlik bilgilerini sağlayın. Sürümlerinde SQL Serverönce SQL Server 2005, işlem yayınına oluşturduğunuzda bu otomatik olarak yapıldı.

  • sp_addqreader_agent:

    Şimdi bağlamını belirtir sp_addqreader_agent (Transact-sql)işi el ile ekleyip, altında sıra Okuyucu Aracısı dağıtımcı çalıştığı Windows kimlik bilgileri sağlamanız için. Sürümlerinde SQL Serverönce SQL Server 2005, kuyruğa alınmış güncelleştirme desteklenen işlem yayınına oluşturduğunuzda bu otomatik olarak yapıldı.

Güvenlik modelini tanıttı SQL Server 2005, bağlantı yerel örneği çoğaltma aracıları her zaman yapmak SQL ServerWindows sağlanan kimlik bilgilerini kullanarak kimlik @ job_name ve @ job_password. Çoğaltma aracısı işleri çalışırken kullanılan Windows hesap gereksinimleri hakkında daha fazla bilgi için bkz: Çoğaltma aracısı güvenlik modeli.

Güvenlik notuGüvenlik Notu

Mümkün olduğunda, zamanında güvenlik kimlik bilgilerini girmesini ister. Kimlik bilgileri bir komut dosyasında depolarsanız, dosyanın güvenli olduğunu emin olun.

Bir anlık görüntü veya işlem yayını yapılandırma komut dosyaları yükseltme

  1. Varolan komut dosyası, önce için yürütme eşdeğerdirsp_addpublication (Transact-sql), idam sp_addlogreader_agent (Transact-sql)Yayını veritabanı üzerinde yayımcı adresindeki. Günlük Okuma Aracısı çalıştığı için Windows kimlik bilgileri belirtmek @ job_name ve @ job_password. Aracı kullanıyorsa, SQL Serveryayımcı bağlanırken kimlik doğrulamasını da değeri belirtmeniz gerekir 0 için @ publisher_security_mode ve SQL Serveriçin oturum açma bilgilerini @ publisher_login ve publisher_password @. Bu bir günlük Okuma Aracısı iş yayını veritabanı için oluşturur.

    [!NOT]

    Bu adım yalnızca işlem yayınlar için ve anlık görüntü yayınlar için gerekli değildir.

  2. (İsteğe bağlı) Önce için yürütme eşdeğerdirsp_addpublication (Transact-sql), idam sp_addqreader_agent (Transact-sql)at dağıtımcı dağıtım veritabanı üzerinde. Altında sıra Okuyucu Aracısı çalıştığı için Windows kimlik bilgileri belirtmek @ job_name ve @ job_password. Bu, bir sıra Okuma Aracısı iş dağıtımcı oluşturur.

    [!NOT]

    Yalnızca bu adımdır gerekli kuyruğa alınmış güncelleştirme aboneleri desteklemek işlem yayınlar için.

  3. (İsteğe bağlı) Yürütme güncelleştirmek için yürütme eşdeğerdirsp_addpublication (Transact-sql)Yeni çoğaltma işlevleri uygulamak parametreler için herhangi bir varsayılan olmayan değer için.

  4. Sonra için yürütme eşdeğerdirsp_addpublication (Transact-sql), idam sp_addpublication_snapshot (Transact-sql)Yayını veritabanı üzerinde yayımcı adresindeki. Belirtmek @ yayın ve anlık görüntü Aracısı çalıştığı için Windows kimlik bilgileri @ job_name ve @ job_password. Aracı kullanıyorsa, SQL Serveryayımcı bağlanırken kimlik doğrulamasını da değeri belirtmeniz gerekir 0 için @ publisher_security_mode ve SQL Serveriçin oturum açma bilgilerini @ publisher_login ve publisher_password @. Bu bir anlık görüntü Aracısı iş yayını oluşturur.

  5. (İsteğe bağlı) Yürütme güncelleştirmek eşdeğerdirsp_addarticle (Transact-sql)Yeni çoğaltma işlevleri uygulamak parametreler için herhangi bir varsayılan olmayan değer için.

Bir anlık görüntü veya işlem yayın abonelikleri Ekle kodları yükseltmek için

Birleştirme yayını yapılandırma komut dosyaları yükseltme

  1. (İsteğe bağlı) Varolan komut dosyasının yürütülmesine güncelleştirmek veyasp_addmergepublication (Transact-sql)Yeni çoğaltma işlevleri uygulamak parametreler için herhangi bir varsayılan olmayan değer için.

  2. Sonra veyasp_addmergepublication (Transact-sql), idam sp_addpublication_snapshot (Transact-sql)Yayını veritabanı üzerinde yayımcı adresindeki. Belirtmek @ yayın ve anlık görüntü Aracısı çalıştığı için Windows kimlik bilgileri @ job_name ve @ job_password. Aracı kullanıyorsa, SQL Serveryayımcı bağlanırken kimlik doğrulamasını da değeri belirtmeniz gerekir 0 için @ publisher_security_mode ve SQL Serveriçin oturum açma bilgilerini @ publisher_login ve publisher_password @. Bu bir anlık görüntü Aracısı iş yayını oluşturur.

  3. (İsteğe bağlı) Yürütme güncelleştirmek yürütmesp_addmergearticle (Transact-sql)Yeni çoğaltma işlevleri uygulamak parametreler için herhangi bir varsayılan olmayan değer için.

Abonelik birleştirme yayınına eklediğiniz komut yükseltmek için

Örnek

Aşağıdaki örnek olduğunu bir SQL Server 2000işlem yayınına ürün tablo oluşturur komut dosyası. Bu yayında, hemen yerine çalışma olarak kuyruğa alınmış güncelleştirme ile güncelleştirmek destekler. Varsayılan parametreler, okunabilirlik için kaldırılmıştır.

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

Yükseltme başarıyla çalıştırmak için işlem yayınına oluşturur önceki komut dosyası örneği verilmektedir SQL Server 2005ve sonraki sürümleri. Bu yayında, hemen yerine çalışma olarak kuyruğa alınmış güncelleştirme ile güncelleştirmek destekler. Yeni parametrelerin varsayılan değerleri açık olarak ilan edilmiştir.

[!NOT]

Windows kimlik bilgilerini kullanarak çalıştırma sağlanacak olan sqlcmd komut dosyası değişkenleri.

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

Aşağıdaki örnek olduğunu bir SQL Server 2000Müşteriler tablosu için birleştirme yayını oluşturur komut dosyası. Varsayılan parametreler, okunabilirlik için kaldırılmıştır.

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

Yükseltme başarıyla çalıştırmak için birleştirme yayını oluşturur önceki komut dosyası örneği şudur SQL Server 2005ve sonraki sürümleri. Yeni parametrelerin varsayılan değerleri açık olarak ilan edilmiştir.

[!NOT]

Windows kimlik bilgilerini kullanarak çalıştırma sağlanacak olan sqlcmd komut dosyası değişkenleri.

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

Aşağıdaki örnek olduğunu bir SQL Server 2000bir itme abonelik işlem yayınına oluşturur komut dosyası. Varsayılan parametreler, okunabilirlik için kaldırılmıştır.

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

Yükseltme başarıyla çalıştırmak için bir işlem yayın için itme abonelik oluşturan önceki komut dosyası örneği şudur SQL Server 2005ve sonraki sürümleri. Yeni parametrelerin varsayılan değerleri açık olarak ilan edilmiştir.

[!NOT]

Windows kimlik bilgilerini kullanarak çalıştırma sağlanacak olan sqlcmd komut dosyası değişkenleri.

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

Aşağıdaki örnek olduğunu bir SQL Server 2000bir itme abonelik birleştirme yayınına oluşturur komut dosyası. Varsayılan parametreler, okunabilirlik için kaldırılmıştır.

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

Başarılı bir şekilde çalıştırmak için yükseltilmiş bir birleştirme yayını itme abonelik oluşturan önceki komut dosyası örneği şudur SQL Server 2005ve sonraki sürümleri. Yeni parametrelerin varsayılan değerleri açık olarak ilan edilmiştir.

[!NOT]

Windows kimlik bilgilerini kullanarak çalıştırma sağlanacak olan sqlcmd komut dosyası değişkenleri.

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

Aşağıdaki örnek olduğunu bir SQL Server 2000, bir çekme abonelik işlem yayınına oluşturur komut dosyası. Varsayılan parametreler, okunabilirlik için kaldırılmıştır.

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

Yükseltme başarıyla çalıştırmak için bir işlem yayın için çekme abonelik oluşturan önceki komut dosyası örneği şudur SQL Server 2005ve sonraki sürümleri. Yeni parametrelerin varsayılan değerleri açık olarak ilan edilmiştir.

[!NOT]

Windows kimlik bilgilerini kullanarak çalıştırma sağlanacak olan sqlcmd komut dosyası değişkenleri.

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

Aşağıdaki örnek olduğunu bir SQL Server 2000, bir çekme abonelik birleştirme yayınına oluşturur komut dosyası. Varsayılan parametreler, okunabilirlik için kaldırılmıştır.

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

Çekme abonelik başarıyla çalıştırmak için yükseltilmiş birleştirme yayınına oluşturur önceki komut dosyası örneği şudur SQL Server 2005ve sonraki sürümleri. Yeni parametrelerin varsayılan değerleri açık olarak ilan edilmiştir.

[!NOT]

Windows kimlik bilgilerini kullanarak çalıştırma sağlanacak olan sqlcmd komut dosyası değişkenleri.

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

Ayrıca bkz.

Kavramlar

Yayın oluşturma

Itme abonelik oluşturma

Çekme abonelik oluştur

View ve çoğaltma güvenlik ayarları değiştir

MSSQL_ENG021797

MSSQL_ENG021798

Yineleme sistem saklı yordamlar kavramları

Yükseltme yinelenmiş veritabanlarını