Add new article to existing publication for SQL Server Transactional Replication
By: Nisarg Upadhyay | Updated: 2018-10-15 | Comments (3) | Related: More > Replication
SQL Server Replication is a great tool to transfer data between different instances of SQL Server as well as other non-SQL Server databases. When setting up replication, you never know what new database changes will occur, so there is often the need to add additional objects to the publication. In this tip we will look at how to add a new article (database object) to an existing SQL Server publication.
In this tip, I am going to demonstrate how to add an article (database object) to an existing replication publication.
I have set up transactional replication as follows:
- Replication Type: Transactional Replication
- Publisher database: AdventureWorks2014 on instance TTI412-VM\SQL2017
- Subscriber database: Customer_DB on instance TTI412-VM
I have a publication named Customer_Publication on the publisher database. The publication has one article which is a table named Customers. Replication has already been setup with the subscriber, so on the subscriber instance the same table, Customers, exists in the database Customer_DB.
According to the concept of transactional replication, row and data changes made on the Customers table at the publisher, replicate to the subscriber table Customers.
The following image illustrates the set-up:
To review the publisher information open SQL Server Management Studio, expand the SQL Instance, expand Replication then expand Local Publications, as shown below. We can see we have a publication called Customer_Publication.
To review the subscriber information open SQL Server Management Studio, expand the SQL Instance, expand Replication and expand Local Subscriptions as shown below:
Alternatively, you can view the replication settings by executing T-SQL queries. You can review the scripts in this article. The following output has been generated after executing the T-SQL scripts.
The Output of Publisher Server:
The Output of Subscriber Server:
Add Article in Replication using SQL Server Management Studio
You can add articles to an existing publication from the Properties window on the publisher server. To open the Properties window, in SQL Server Management Studio, expand Replication, expand Local Publications and right click on the Customer_Publication and select Properties as shown below.
A publication Properties dialog box opens. In the dialog box, select the Articles page. It populates the list of objects which are already part of the publication. We can see we only have the Customers table as part of this publication.
To get a list of all database objects, un-check the checkbox for Show only checked articles in the list as shown below. Then select the list of database objects to add to the existing publication. Below I have highlighted the five tables I will add to the publication. After selecting the objects, click OK to close the dialog box.
After adding the articles to the existing publication, we must re-initialize the subscriptions with a new snapshot. To do that, right click on the publication and select Reinitialize All Subscriptions as shown below.
A dialog box Reinitialize Subscription(s) opens. Select Use a new snapshot and then click the Mark For Reinitialization button.
We must create a new snapshot after adding the new articles. The new snapshot can be generated using Replication Monitor. To open Replication Monitor, right click on the Customer_Publication and select Launch Replication Monitor as shown below.
When Replication Monitor opens, click on the Agents tab. In the dropdown select Snapshot Agent from the Agent types. From the list of snapshot agents, right click on [AdventureWorks2014].[Customer_Publication] and select Start Agent as shown below.
Once the Snapshot Agent runs, you can view the process in the Last Action.
Alternatively, you can run the snapshot job from the View Snapshot Agent Status dialog box. To open it, expand Local publications and right click on Customer_Publication and select View Snapshot Agent Status. In the dialog box, click the Start button. You can see the status of a snapshot process in Status text box.
Once the snapshot job completes, the new articles will be added to the subscribers. To verify, connect to the subscriber database and execute the following query.
use Customer_DBgo select name,create_date,type_desc from sys.tables where name not like '%MS%'
Following is the output of the above query. This shows all of the tables that now exist in the Customer_DB database on the subscriber.
Let's check the status of the publisher and subscriber. To do that, re-execute the queries we used above.
The Output of Publisher Server:
In this tip, I have explained how to add an article to existing transactional replication publication.
Last Updated: 2018-10-15
About the author
View all my tips