-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathsp-link-publication-tran_1.sql
More file actions
67 lines (60 loc) · 2.24 KB
/
sp-link-publication-tran_1.sql
File metadata and controls
67 lines (60 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables
-- on the command line and in SQL Server Management Studio, see the
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".
-- Execute this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS nvarchar(512);
SET @publication = N'AdvWorksProductTran';
SET @publicationDB = N'AdventureWorks2012';
SET @publisher = $(PubServer);
SET @login = $(Login);
SET @password = $(Password);
-- At the subscription database, create a pull subscription to a transactional
-- publication using immediate updating with queued updating as a failover.
EXEC sp_addpullsubscription
@publisher = @publisher,
@publication = @publication,
@publisher_db = @publicationDB,
@update_mode = N'failover',
@subscription_type = N'pull';
-- Add an agent job to synchronize the pull subscription,
-- which uses Windows Authentication when connecting to the Distributor.
EXEC sp_addpullsubscription_agent
@publisher = @publisher,
@publisher_db = @publicationDB,
@publication = @publication,
@job_login = @login,
@job_password = @password;
-- Add a Windows Authentication-based linked server that enables the
-- Subscriber-side triggers to make updates at the Publisher.
EXEC sp_link_publication
@publisher = @publisher,
@publication = @publication,
@publisher_db = @publicationDB,
@security_mode = 0,
@login = @login,
@password = @password;
GO
USE AdventureWorks2012
GO
-- Execute this batch at the Publisher.
DECLARE @publication AS sysname;
DECLARE @subscriptionDB AS sysname;
DECLARE @subscriber AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @subscriptionDB = N'AdventureWorks2012Replica';
SET @subscriber = $(SubServer);
-- At the Publisher, register the subscription, using the defaults.
USE [AdventureWorks2012]
EXEC sp_addsubscription
@publication = @publication,
@subscriber = @subscriber,
@destination_db = @subscriptionDB,
@subscription_type = N'pull',
@update_mode = N'failover';
GO