I would like to add a column to a published table but not have that column replicated to subscribers. I can accomplish this via the UI by adding the column and then unchecking it. This adds the column to the publisher table but does not replicate it to the subscriber.
I am looking for a programmatic method to add a column to the base table and unmark it for replication.
Thanks for your assistance.
Here is a TSQL example (I suppose you mean SQL Server 2005):
1. First turn replication_ddl property off for your publication
exec sp_changepublication @.publication = 'pubname'
, @.property = 'replicate_ddl'
, @.value = '0'
, @.force_invalidate_snapshot = 0
, @.force_reinit_subscription = 0
2. Execute DDL statement to add a new column:
alter table authors add newcol8 int not null default 0
3. If you want to turn schema/DDL replication on for subsequent add columns, then turn it back on:
exec sp_changepublication @.publication = 'pubname'
, @.property = 'replicate_ddl'
, @.value = '1'
, @.force_invalidate_snapshot = 0
, @.force_reinit_subscription = 0
Hope that helps,
Zhiqiang Feng
This posting is provided "AS IS" with no warranties, and confers no rights.
Another option you can have is vertical partitioning with which you can filter out which columns you want to publisher and which ones you do not want to.
When you mention that you could achieve this by doing in the UI, this is what is internally happening. The table is enabled for vertical partitioning and the newly added column is removed from the partition when you uncheck this column
Look in BOL for:sp_mergearticlecolumn, sp_articlecolumn, vertical_partition parameter of sp_addarticle/sp_addmergearticle
No comments:
Post a Comment