how to drop a replicated table in both the publication and subscription

hofnarwillie picture hofnarwillie · May 8, 2012 · Viewed 11k times · Source

How do I drop a replicated table in the publication as well as the subscription? (scripts only)

I do not want to remove it from replication only, because then an unreplicated copy of the table will remain on the subscriptions. I want all instances of the table removed.

So I want a script that removes a table from a publisher, and removes the table from the publication and also drops the table in the publisher and all subscribers. Ideally it would take a parameter of the table name.

Answer

Brandon Williams picture Brandon Williams · May 8, 2012

You will need to call sp_droparticle or sp_dropmergearticle to delete the article from the publication, then generate a new snapshot.

Then call DROP table to delete the table at both publisher and subscriber(s).

This is covered in both Add Articles to and Drop Articles from Existing Publications and Delete an Article.

To post the DROP statements to subscribers from the publisher, use sp_addscriptexec.