-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathconfigure-snapshot-prope_1.sql
More file actions
53 lines (47 loc) · 1.66 KB
/
configure-snapshot-prope_1.sql
File metadata and controls
53 lines (47 loc) · 1.66 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
-- 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".
--Declarations for adding a merge publication
DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
DECLARE @article AS sysname;
DECLARE @owner AS sysname;
DECLARE @snapshot_share AS sysname;
SET @publicationDB = N'AdventureWorks2012';
SET @publication = N'AdvWorksSalesOrdersMergeAltSnapshot';
SET @article = N'SpecialOffer';
SET @owner = N'Sales';
SET @snapshot_share = '\\' + $(InstanceName) + '\AltSnapshotFolder';
-- Enable merge replication on the publication database, using defaults.
USE master
EXEC sp_replicationdboption
@dbname = @publicationDB,
@optname=N'merge publish',
@value = N'true';
-- Create new merge publication with an alternate snapshot location.
USE [AdventureWorks]
EXEC sp_addmergepublication
-- required parameters
@publication = @publication,
@snapshot_in_defaultfolder = N'false',
@alt_snapshot_folder = @snapshot_share,
@compress_snapshot = N'true';
-- Create the snapshot job for the publication.
EXEC sp_addpublication_snapshot
@publication = @publication,
@job_login = $(Login),
@job_password = $(Password);
-- Add an article.
EXEC sp_addmergearticle
@publication = @publication,
@article = @article,
@source_object = @article,
@type = N'table',
@source_owner = @owner,
@destination_owner = @owner;
-- Start the snapshot job.
EXEC sp_startpublication_snapshot
@publication = @publication;
GO