Many times I have found myself needing to make changes to an existing table that is being published for replication. Here is a script that I have been using for a few years now that has served me well and never caused issues. Hope you find it useful.
-- @publication is the name of the Replication Publication
-- @article is the name of the table you want to alter
-- @subcriber is the computer name where the Replication Subscription is
-- @destination_db is the name of the database
exec sp_dropsubscription @publication = 'DATABASENAME'
, @article = 'TABLENAME'
, @subscriber = 'SERVERNAME'
, @destination_db = 'DATABASENAME'
exec sp_droparticle @publication = 'DATABASENAME'
, @article = 'TABLENAME'
-- Write your alter statement here
alter table TABLENAME alter column columnName varchar(2000) null
exec sp_addarticle @publication = 'DATABASENAME'
, @article = 'TABLENAME'
, @source_table = 'TABLENAME'
exec sp_addsubscription @publication = 'DATABASENAME'
, @article = 'TABLENAME'
, @subscriber = 'SERVERNAME'
, @destination_db = 'DATABASENAME'
Posted
May 06 2008, 08:13 PM
by
dacrowlah