Created
April 28, 2017 10:39
-
-
Save anonymous/59cbf198abe06612c6aa722b987ce55c to your computer and use it in GitHub Desktop.
Query to create a pull subscripton for SQL Server replication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [Database]; | |
-- Execute this batch at the Subscriber. | |
DECLARE @iPublisher AS sysname; | |
DECLARE @iPublication AS sysname; | |
DECLARE @iPublicationDB AS sysname; | |
DECLARE @iSubscriber AS sysname; | |
DECLARE @iSubscriptionDB AS sysname; | |
SET @iPublisher = N'PublisherName'; | |
SET @iPublication = N'PublicationName'; | |
SET @iPublicationDB = N'PublisherDatabase'; | |
SET @iSubscriber = @@SERVERNAME; | |
SELECT @iSubscriptionDB = DB_NAME(); | |
-- At the subscriber database, create a pull subscription to a transactional or snapshot publication. | |
EXEC sys.sp_addpullsubscription @publisher = @iPublisher, | |
@publication = @iPublication, | |
@publisher_db = @iPublicationDB; | |
--Execute the outputed query at the Publisher to register the subscriber | |
SELECT 'EXEC sys.sp_addsubscription @publication = ''' + @iPublication + ''', @subscriber = ''' + @iSubscriber | |
+ ''', @destination_db = ''' + @iSubscriptionDB | |
+ ''', @subscription_type = N''pull'', @status = N''subscribed'';' AS 'Run on publisher'; | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment