Megosztás a következőn keresztül:


Replikációs szkriptek frissítése (replikációs Transact-SQL programozás)

A következőkre vonatkozik:SQL ServerAzure SQL Managed Instance

Transact-SQL szkriptfájlokkal programozott módon konfigurálhat replikációs topológiát. További információkért lásd a replikációs rendszer tárolt eljárásainak alapelveit.

Fontos

Bár nem kell frissítenie a sysadmin szerepkör tagjai által végrehajtott szkripteket, javasoljuk, hogy módosítsa a meglévő szkripteket a jelen témakörben leírtak szerint. Adjon meg egy fiókot, amely minimális engedélyekkel rendelkezik az egyes replikációs ügynökökhöz a replikációs ügynök biztonsági modellje című témakör "Az ügynökök által szükséges engedélyek" című szakaszában leírtak szerint.

Ezek a biztonsági fejlesztések, amelyek lehetővé teszik az engedélyek nagyobb ellenőrzését azáltal, hogy lehetővé teszik a replikációs ügynök feladatainak végrehajtásához szükséges Microsoft Windows-fiókok explicit megadását, a meglévő szkriptekben a következő tárolt eljárásokat érintik:

  • sp_addpublication_snapshot:

    Most meg kell adnia a Windows hitelesítő adatait @job_login@job_password a sp_addpublication_snapshot (Transact-SQL) végrehajtásakor annak a feladatnak a létrehozásához, amely alatt a Pillanatkép-ügynök fut a forgalmazónál.

  • sp_addpushsubscription_agent:

    Most hajtsa végre a sp_addpushsubscription_agent (Transact-SQL) parancsot, hogy kifejezetten hozzáadjon egy feladatot, és megadja azokat a Windows-hitelesítő adatokat (@job_login és @job_password), amelyek alatt az elosztási ügynök feladata fut a forgalmazónál. Az SQL Server 2005 (9.x) előtti SQL Server-verziókban ez automatikusan megtörtént egy leküldéses előfizetés létrehozásakor.

  • sp_addmergepushsubscription_agent:

    Most végre kell hajtania a sp_addmergepushsubscription_agent (Transact-SQL) parancsot, hogy explicit módon adjon hozzá egy feladatot, és adja meg azokat a Windows-hitelesítő adatokat (@job_login és @job_password) amelyek alatt az egyesítési ügynök feladat a forgalmazónál fut. Az SQL Server 2005 (9.x) előtti SQL Server-verziókban ez automatikusan megtörtént egy leküldéses előfizetés létrehozásakor.

  • sp_addpullsubscription_agent:

    Most meg kell adnia a Windows-hitelesítő adatokat mint @job_login és @job_password a sp_addpullsubscription_agent (Transact-SQL) végrehajtásakor, hogy létrehozza azt a feladatot, amely alatt a Terjesztési Ügynök az Előfizetőnél fut.

  • sp_addmergepullsubscription_agent:

    Most meg kell adnia a Windows-hitelesítő adatokat @job_login és @job_password, amikor végrehajtja a sp_addmergepullsubscription_agent (Transact-SQL), hogy létrehozza azt a feladatot, amely alatt az Egyesítési Ügynök az Előfizetőnél fut.

  • sp_addlogreader_agent:

    Most hajtsa végre a sp_addlogreader_agent (Transact-SQL) parancsot a feladat kézi hozzáadásához, és adja meg a Windows hitelesítő adatokat, amelyek alatt a Log Reader Agent fut a Distributornál. Az SQL Server 2005 (9.x) előtti SQL Server-verziókban ez automatikusan megtörtént egy tranzakciós kiadvány létrehozásakor.

  • sp_addqreader_agent:

    Most hajtsa végre a sp_addqreader_agent (Transact-SQL) parancsot a feladat manuális hozzáadásához és adja meg a Windows hitelesítő adatait, amelyek alatt az üzenetsor-olvasó ügynök fut a forgalmazónál. Az SQL Server SQL Server 2005 (9.x) előtti verzióiban ez automatikusan megtörtént, amikor létrejött egy tranzakciós kiadvány, amely támogatja az üzenetsorok frissítését.

Az SQL Server 2005 -ben bevezetett biztonsági modellben (9.x) a replikációs ügynökök mindig kapcsolatot létesítenek az SQL Server helyi példányával Windows-hitelesítéssel a megadott @job_name hitelesítő adatokkal.@job_password A replikációs ügynök feladatainak futtatásakor használt Windows-fiókok követelményeiről további információt a replikációs ügynök biztonsági modelljében talál.

Fontos

Ha lehetséges, kérje meg a felhasználókat, hogy futásidőben adjanak meg biztonsági hitelesítő adatokat. Ha szkriptfájlban tárolja a hitelesítő adatokat, győződjön meg arról, hogy maga a fájl védett.

Pillanatképet vagy tranzakciós kiadványt konfiguráló szkriptek frissítése

  1. A meglévő szkriptben sp_addpublication (Transact-SQL) előtt hajtsa végre sp_addlogreader_agent (Transact-SQL) a Publisherben a közzétételi adatbázisban. Adja meg azokat a Windows-hitelesítő adatokat, amelyek alatt a Naplóolvasó-ügynök fut @job_name és @job_password. Ha az ügynök SQL Server-hitelesítést fog használni a Publisherhez való csatlakozáskor, meg kell adnia a 0@publisher_security_mode értéket, valamint az SQL Server bejelentkezési adatait @publisher_login és @publisher_passworda . Ez létrehoz egy Naplóolvasóügynök-feladatot a kiadványadatbázishoz.

    Megjegyzés:

    Ez a lépés csak tranzakciós kiadványokra vonatkozik, és nem szükséges pillanatkép-kiadványokhoz.

  2. (Nem kötelező) A sp_addpublication (Transact-SQL) előtt hajtsa végre sp_addqreader_agent (Transact-SQL) a terjesztési adatbázis forgalmazójánál. Adja meg azokat a Windows-hitelesítő adatokat, amelyek alatt a várólista-olvasó ügynök fut @job_name és @job_password. Ezzel létrehoz egy Üzenetsor-olvasó ügynök feladatot a forgalmazó számára.

    Megjegyzés:

    Ez a lépés csak olyan tranzakciós kiadványokhoz szükséges, amelyek támogatják az előfizetők várólistára helyezését.

  3. (Nem kötelező) Frissítse a sp_addpublication (Transact-SQL) végrehajtását az új replikációs funkciókat megvalósító paraméterek nem alapértelmezett értékeinek beállításához.

  4. A sp_addpublication (Transact-SQL) után hajtsa végre a sp_addpublication_snapshot (Transact-SQL) a Publisherben a közzétételi adatbázisban. Adja meg @publication és a Windows-hitelesítő adatokat, amelyeken a Pillanatkép-ügynök fut @job_name és @job_password alatt. Ha az ügynök SQL Server-hitelesítést fog használni a Publisherhez való csatlakozáskor, meg kell adnia a 0@publisher_security_mode értéket, valamint az SQL Server bejelentkezési adatait @publisher_login és @publisher_passworda . Ez létrehoz egy Pillanatkép-ügynök feladatot a kiadványhoz.

  5. (Nem kötelező) Frissítse a sp_addarticle (Transact-SQL) végrehajtását az új replikációs funkciókat megvalósító paraméterek nem alapértelmezett értékeinek beállításához.

Szkriptek frissítése, amelyek előfizetéseket adnak egy pillanatképhez vagy tranzakciós kiadványhoz.

  1. Az előfizetést létrehozó tárolt eljárás végrehajtása után győződjön meg arról, hogy végrehajtja azt a tárolt eljárást, amely létrehoz egy Terjesztési ügynök feladatot az előfizetés szinkronizálásához. A tárolt eljárás, amelyet használni fog, az előfizetés típusától függ.

Egyesítési publikáció konfigurálásához használt szkriptek frissítése

  1. (Nem kötelező) A meglévő szkriptben frissítse a sp_addmergepublication (Transact-SQL) végrehajtását az új replikációs funkciókat megvalósító paraméterek nem alapértelmezett értékeinek beállításához.

  2. A sp_addmergepublication (Transact-SQL) után hajtsa végre a sp_addpublication_snapshot (Transact-SQL)-et a közzétételi adatbázisban a Publisheren. Adja meg @publication és a Windows-hitelesítő adatokat, amelyeken a Pillanatkép-ügynök fut @job_name és @job_password alatt. Ha az ügynök SQL Server-hitelesítést fog használni a Publisherhez való csatlakozáskor, meg kell adnia a 0@publisher_security_mode értéket, valamint az SQL Server bejelentkezési adatait @publisher_login és @publisher_passworda . Ez létrehoz egy Pillanatkép-ügynök feladatot a kiadványhoz.

  3. (Nem kötelező) Frissítse a sp_addmergearticle (Transact-SQL) végrehajtását az új replikációs funkciókat megvalósító paraméterek nem alapértelmezett értékeinek beállításához.

Olyan szkriptek frissítése, amelyek előfizetéseket adnak hozzá egy egyesítési kiadványhoz

  1. Az előfizetést létrehozó tárolt eljárás végrehajtása után győződjön meg arról, hogy végrehajtja azt a tárolt eljárást, amely létrehoz egy Egyesítési ügynök feladatot az előfizetés szinkronizálásához. A tárolt eljárás, amelyet használni fog, az előfizetés típusától függ.

Példák

Egy. SQL Server 2000-szkript tranzakciós kiadvány létrehozásához

Az alábbiakban egy példa egy SQL Server 2000 (8.x) szkriptre, amely tranzakciós kiadványt hoz létre a Product táblához. Ez a közzététel az azonnali frissítést és az üzenetsoros frissítést támogatja túlterhelés esetén. Az alapértelmezett paraméterek el lettek távolítva az olvashatóság érdekében.

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 és újabb szkript tranzakciós kiadvány létrehozásához

Az alábbiakban egy példa látható az előző szkript frissítésére, amely tranzakciós kiadványt hoz létre az SQL Server 2005 (9.x) és újabb verziók sikeres futtatásához. Ez a közzététel az azonnali frissítést és az üzenetsoros frissítést támogatja túlterhelés esetén. Az új paraméterek alapértelmezései explicit módon lettek deklarálva.

Megjegyzés:

A Windows hitelesítő adatai futásidőben, sqlcmd szkriptelési változók használatával lesznek megadva.

-- 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-szkript egyesítési kiadvány létrehozásához

Az alábbi példa egy SQL Server 2000 (8.x) szkriptre mutat be, amely egy egyesítési kiadványt hoz létre az Ügyfelek táblához. Az alapértelmezett paraméterek el lettek távolítva az olvashatóság érdekében.

-- 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 vagy újabb esetén szkript az egyesítési kiadvány létrehozásához.

Az alábbiakban egy példa látható az előző szkriptre, amely létrehoz egy egyesítési kiadást, és amelyet frissítettek, hogy sikeresen fusson az SQL Server 2005 és az újabb verziók esetében. Az új paraméterek alapértelmezései explicit módon lettek deklarálva.

Megjegyzés:

A Windows hitelesítő adatai futásidőben, sqlcmd szkriptelési változók használatával lesznek megadva.

-- 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-szkript leküldéses előfizetés létrehozásához tranzakciós kiadványhoz

Az alábbiakban egy példa egy SQL Server 2000 (8.x) szkriptre, amely leküldéses előfizetést hoz létre egy tranzakciós kiadványhoz. Az alapértelmezett paraméterek el lettek távolítva az olvashatóság érdekében.

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 és újabb verzióihoz készült szkript, amely tranzakciós kiadványhoz előfizetés létrehozását szolgálja.

Az alábbiakban egy példa látható az előző szkriptre, amely leküldéses előfizetést hoz létre egy tranzakciós kiadványhoz, amelyet sikeresen frissítettünk az SQL Server 2005 (9.x) és újabb verzióihoz. Az új paraméterek alapértelmezései explicit módon lettek deklarálva.

Megjegyzés:

A Windows hitelesítő adatai futásidőben, sqlcmd szkriptelési változók használatával lesznek megadva.

-- 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-szkript egy leküldéses előfizetés létrehozásához egy egyesítési publikációhoz

Az alábbi példa egy SQL Server 2000 (8.x) szkriptre mutat be, amely leküldéses előfizetést hoz létre egy egyesítési kiadványhoz. Az alapértelmezett paraméterek el lettek távolítva az olvashatóság érdekében.

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-ös és újabb szkript leküldéses előfizetés létrehozásához egy egyesítési kiadványhoz

Az alábbiakban egy példa látható az előző szkriptre, amely leküldéses előfizetést hoz létre egy egyesítési kiadványhoz, amelyet az SQL Server 2005 (9.x) és újabb verziók sikeres futtatására frissítettek. Az új paraméterek alapértelmezései explicit módon lettek deklarálva.

Megjegyzés:

A Windows hitelesítő adatai futásidőben, sqlcmd szkriptelési változók használatával lesznek megadva.

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

Én. SQL Server 2000-szkript lekéréses előfizetés létrehozásához tranzakciós kiadványhoz

Az alábbiakban egy példa egy SQL Server 2000 (8.x) szkriptre, amely lekéréses előfizetést hoz létre egy tranzakciós kiadványhoz. Az alapértelmezett paraméterek el lettek távolítva az olvashatóság érdekében.

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-ös és újabb szkript egy tranzakciós kiadvány lekéréses előfizetésének létrehozásához

Az alábbiakban egy példa látható az előző szkriptre, amely lekéréses előfizetést hoz létre egy tranzakciós kiadványhoz, amelyet az SQL Server 2005 (9.x) és újabb verziók sikeres futtatására frissítettek. Az új paraméterek alapértelmezései explicit módon lettek deklarálva.

Megjegyzés:

A Windows hitelesítő adatai futásidőben, sqlcmd szkriptelési változók használatával lesznek megadva.

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

K. SQL Server 2000-szkript lekéréses előfizetés létrehozásához egyesítési kiadványhoz

Az alábbi példa egy SQL Server 2000 (8.x) szkriptre mutat be, amely lekéréses előfizetést hoz létre egy egyesítési kiadványhoz. Az alapértelmezett paraméterek el lettek távolítva az olvashatóság érdekében.

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

L. SQL Server 2005 és újabb verziókhoz írt szkript a lekérdezési előfizetés létrehozásához az egyesítési kiadványhoz

Az alábbiakban egy példa látható az előző szkriptre, amely lekéréses előfizetést hoz létre egy egyesítési kiadványhoz, amelyet az SQL Server 2005 (9.x) és újabb verziók sikeres futtatására frissítettek. Az új paraméterek alapértelmezései explicit módon lettek deklarálva.

Megjegyzés:

A Windows hitelesítő adatai futásidőben, sqlcmd szkriptelési változók használatával lesznek megadva.

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