Saturday 14 December 2019

Add a new table to existing publication

Add a new table to existing publication

use dbname
go
EXEC sp_changepublication
@publication = ' Pub_name',
@property = N'allow_anonymous',
@value = 'false'
GO


EXEC sp_changepublication
@publication = 'pub_name'
@property = N'immediate_sync',
@value = 'false'
GO

EXEC sp_addarticle  @publication = N'Pub_name',
@article = N'Time',
@source_object=N'Time'
GO

 --same above if you another table


--Should run on publisher
EXEC sp_refreshsubscriptions @publication = N'Pub_name'
GO

 ----Should run on publisher
EXEC sp_startpublication_snapshot @publication = N'Pub_name'
go


Removing a table from replication

--remove table from replication
 EXEC  sys.sp_dropsubscription
    @publication = N'Pub_name',
    @article = N'Time',
    @subscriber = N'SQL4',
    @destination_db = 'db_name'' ;
GO


EXEC sys.sp_droparticle
    @publication = N'Pub_name',
    @article = N'Time',
    @force_invalidate_snapshot = 1 ;
GO

0 comments:

Post a Comment