Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server script to remove replication?

I have been asked to write a SQL script that can be run, which will stop replication and remove the subscriber/subscription.

Is this at all possible? Or do you have to use the GUI?

like image 570
Craig Avatar asked Jun 29 '11 08:06

Craig


People also ask

How do I completely remove replication in SQL Server?

To remove a replication, you must drop the subscriptions, the publications, and the distributor that is configured for the replication. You can remove the replication by running the Transact-SQL script that is generated by SQL Server Enterprise Manager or SQL Server Management Studio.

How do I temporarily disable replication in SQL Server?

Connect to the Publisher or Distributor you want to disable in Microsoft SQL Server Management Studio, and then expand the server node. Right-click the Replication folder, and then click Disable Publishing and Distribution.

How do I turn off replication?

To disable replication of multiple databases Select the databases for which you want to disable replication. From Tools, click Database > Replication, or drag the selected databases to the Replication tool. Select Disable.


2 Answers

Which version of SQL Server you are using.

Try

sp_removedbreplication 'DB_PROD' 
go

Related Read - How to cleanup Replication Bits - http://blogs.msdn.com/b/repltalk/archive/2010/11/17/how-to-cleanup-replication-bits.aspx

Google as well provides MSDN article in results

How to: Disable Publishing and Distribution (Replication Transact-SQL Programming) - http://msdn.microsoft.com/en-us/library/ms147921.aspx

like image 50
Siva Avatar answered Oct 21 '22 00:10

Siva


If you're look to completely remove replication, including all the "bits". Or your server only has one publication and this is the one you're trying to remove.

I would recommend:

  1. Connect to the Publisher or Distributor you want to disable in Microsoft SQL Server Management Studio, and then expand the server node.
  2. Right-click the Replication folder, and then click Disable Publishing and Distribution.
  3. Follow the steps in the Disable Publishing and Distribution Wizard, and instead of processing select the option to generate scripts.

This has the advantage of not only completely cleaning things up. But also removing the distribution database, which if you've ever dealt with before is known to become littered with remnants of replications past.

Full documentation can be found here.

like image 39
pim Avatar answered Oct 20 '22 22:10

pim