プル サブスクリプションを削除する方法 (レプリケーション Transact-SQL プログラミング)

プル サブスクリプションは、レプリケーション ストアド プロシージャを使用してプログラムで削除できます。使用するストアド プロシージャは、サブスクリプションが属するパブリケーションの種類によって変わります。

スナップショット パブリケーションまたはトランザクション パブリケーションに対するプル サブスクリプションを削除するには

  1. サブスクライバ側のサブスクリプション データベースに対して、sp_droppullsubscription (Transact-SQL) を実行します。@publication@publisher、および @publisher_db を指定します。

  2. パブリッシャ側のパブリケーション データベースに対して、sp_dropsubscription (Transact-SQL) を実行します。@publication@subscriber を指定します。@articleall を指定します。(省略可) ディストリビュータにアクセスできない場合、@ignore_distributor1 を指定して、ディストリビュータの関連オブジェクトを削除せずにサブスクリプションを削除します。

マージ パブリケーションに対するプル サブスクリプションを削除するには

  1. サブスクライバ側のサブスクリプション データベースに対して、sp_dropmergepullsubscription (Transact-SQL) を実行します。@publication@publisher、および @publisher_db を指定します。

  2. パブリッシャ側のパブリケーション データベースに対して、sp_dropmergesubscription (Transact-SQL) を実行します。@publication@subscriber、および @subscriber_db を指定します。@subscription_type には pull を指定します。(省略可) ディストリビュータにアクセスできない場合、@ignore_distributor1 を指定して、ディストリビュータの関連オブジェクトを削除せずにサブスクリプションを削除します。

使用例

次の例では、トランザクション パブリケーションへのプル サブスクリプションを削除します。最初のバッチはサブスクライバで実行され、次のバッチはパブリッシャで実行されます。

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- This is the batch executed at the Subscriber to drop 
-- a pull subscription to a transactional publication.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB     AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2008R2';

USE [AdventureWorks2008R2Replica]
EXEC sp_droppullsubscription 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication;
GO
-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- This batch is executed at the Publisher to remove 
-- a pull or push subscription to a transactional publication.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @subscriber = $(SubServer);

USE [AdventureWorks2008R2;]
EXEC sp_dropsubscription 
  @publication = @publication, 
  @article = N'all',
  @subscriber = @subscriber;
GO

次の例では、マージ パブリケーションに対するプル サブスクリプションを削除します。最初のバッチはサブスクライバで実行され、次のバッチはパブリッシャで実行されます。

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- This batch is executed at the Subscriber to remove 
-- a merge pull subscription.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publication_db AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @publisher = $(PubServer);
SET @publication_db = N'AdventureWorks2008R2';

USE [AdventureWorks2008R2Replica]
EXEC sp_dropmergepullsubscription 
  @publisher = @publisher, 
  @publisher_db = @publication_db, 
  @publication = @publication;
GO
-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- This batch is executed at the Publisher to remove 
-- a pull or push subscription to a merge publication.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @subscriber = $(SubServer);
SET @subscriptionDB = N'AdventureWorks2008R2Replica';

USE [AdventureWorks2008R2]
EXEC sp_dropmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB;
GO