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

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

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

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

  2. サブスクライバ側のサブスクリプション データベースに対して sp_subscription_cleanup (Transact-SQL) を実行し、サブスクリプション データベースのレプリケーション メタデータを削除します。

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

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

  2. サブスクライバ側のサブスクリプション データベースに対して、sp_mergesubscription_cleanup (Transact-SQL) を実行します。@publisher@publisher_db、および @publication を指定します。これにより、サブスクリプション データベースのマージ メタデータが削除されます。

使用例

次の例では、トランザクション パブリケーションに対するプッシュ サブスクリプションを削除します。

-- 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 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