Monday, February 8, 2010

Manually Remove Replication Script


http://www.replicationanswers.com/Script20.asp

This is a collection of scripts to remove undesired merge rowguid columns after removing the publication. It can be run on the publisher or subscriber. Make sure no other programming objects refer to these objects first (see Vyas's script for this)
Run each of these in turn and then run the output (backup your database
first :))

-- drop rowguid indexes
select 'drop index ' + sysobjects.name + '.' + sysindexes.name from
sysindexes
inner join sysobjects
on sysindexes.id = sysobjects.id
where objectproperty(object_id(sysobjects.name),'IsMSShipped') = 0
and sysindexes.indid > 0 and sysindexes.indid < 255 and (sysindexes.status &
64)=0
and index_col(sysobjects.name, sysindexes.indid, 1) = 'rowguid'
order by sysindexes.indid

-- remove rowguid default constraints
select 'alter table ' + b.name + ' drop constraint ' + a.name from
sysobjects a
inner join syscolumns on syscolumns.id = a.parent_obj
inner join sysobjects b on syscolumns.id = b.id
where syscolumns.name = 'rowguid'
and objectproperty(object_id(b.name),'IsMSShipped') = 0
and a.xtype = 'D'

-- remove rowguid columns
select 'alter table ' + sysobjects.name + ' drop column rowguid ' from
syscolumns
inner join sysobjects on syscolumns.id = sysobjects.id
where syscolumns.name = 'rowguid'
and objectproperty(object_id(sysobjects.name),'IsMSShipped') = 0

~~~~~~~~~MODS TO THE SCRIPT~~~~~~~~~~~~~~~~~~~~
-- remove rowguid columns (for electoral)
select 'alter table ' + sysobjects.name + ' drop column rowguid ' from
syscolumns
inner join sysobjects on syscolumns.id = sysobjects.id
where syscolumns.name = 'rowguid'
and objectproperty(object_id(sysobjects.name),'IsMSShipped') = 0
and sysobjects.name like 'udt%'
order by sysobjects.name