I've previosuly managed articles through T SQL in replication, anyone who has had to make changes to a replicated table will know the pain I'm sure. When there are lots of articles and data is in the hundreds of gigabytes the whole process of making changes can be time consuming, especially if the development environment that created the release scripts didn't have replication - well why make the DBA's job easy?
My task is to totally script transactional replication, so that it is a repeatable and recordable process, in controlled environments using the GUI or a wizard is not an option.
My subscriber doesn't have to update the publisher but it must be a fully functional database that a copy of the application(s) can connect to and work as if in production, a parallel support environment if you like. I have a the usual issues to resolve, timestamp columns, identity columns and so on.
Doing the whole thing has proved interesting and will produce copious documentation, I'll post the various scripts and solutions as I work through the documentation. I've just discovered that articles must be added in order of dependency ( well I know it seems obvious now! ) I'd added a view as a test without the table, got an error so no problem just add the table and off we go then. But no it doesn't work like that, have to remove the view, add the table and then re-add the view.
so simple script to remove a table, make a modification, and add it back to replication.
--
-- remove article from replication
--
exec dbo.sp_dropsubscription @publication='mydb-to-myotherdb',@article='tabletochnage',@subscriber='ServerXXXX'
exec dbo.sp_droparticle @publication='mydb-to-myotherdb',@article='tabletochnage',@force_invalidate_snapshot=1
exec dbo.sp_refreshsubscriptions 'mydb-to-myotherdb'
go
--
alter table tabletochnage drop constraint PK_with_silly_name
go
alter table tabletochnage add constraint PK_tabletochnage primary key clustered (id) with fillfactor = 100
go
--
exec dbo.sp_addarticle 'mydb-to-myotherdb',@article='tabletochnage',@source_table='tabletochnage',@destination_table='tabletochnage',
@force_invalidate_snapshot=1
exec dbo.sp_refreshsubscriptions 'mydb-to-myotherdb'
go
--
exec msdb.dbo.sp_start_job @job_name='the snapshot job'
go
--