共用方式為


如何:刪除發行項 (複寫 Transact-SQL 程式設計)

您可以使用複寫預存程序來以程式設計的方式刪除發行項。使用哪些預存程序要依發行項所屬的發行集類型而定。如需有關可以卸除發行項的情況以及發行項是否需要新快照集或重新初始化訂閱的詳細資訊,請參閱<在現有發行集中加入和卸除發行項>。

從快照式或交易式發行集中刪除發行項

  1. @publication 指定的發行集執行 sp_droparticle (Transact-SQL) 來刪除 @article 指定的發行項。為 @force_invalidate_snapshot 指定 1 的值。

  2. (選擇性) 若要從資料庫完全移除發行的物件,請在發行集資料庫的發行者上執行 DROP <objectname> 命令。

從合併式發行集中刪除發行項

  1. @publication 指定的發行集執行 sp_dropmergearticle (Transact-SQL) 來刪除 @article 指定的發行項。必要時,請為 @force_invalidate_snapshot 指定 1 的值,並為 @force_reinit_subscription 指定 1 的值。

  2. (選擇性) 若要從資料庫完全移除發行的物件,請在發行集資料庫的發行者上執行 DROP <objectname> 命令。

範例

下列範例會刪除交易式發行集中的發行項。由於這項變更會讓現有的快照集失效,所以會針對 @force_invalidate_snapshot 參數指定 1 的值。

DECLARE @publication AS sysname;
DECLARE @article AS sysname;
SET @publication = N'AdvWorksProductTran'; 
SET @article = N'Product'; 

-- Drop the transactional article.
USE [AdventureWorks2008R2]
EXEC sp_droparticle 
  @publication = @publication, 
  @article = @article,
  @force_invalidate_snapshot = 1;
GO

下列範例會刪除合併式發行集中的兩個發行項。由於這些變更會讓現有的快照集失效,所以會針對 @force_invalidate_snapshot 參數指定 1 的值。

DECLARE @publication AS sysname;
DECLARE @table1 AS sysname;
DECLARE @table2 AS sysname;
DECLARE @table3 AS sysname;
DECLARE @salesschema AS sysname;
DECLARE @hrschema AS sysname;
DECLARE @filterclause AS nvarchar(1000);
SET @publication = N'AdvWorksSalesOrdersMerge'; 
SET @table1 = N'Employee'; 
SET @table2 = N'SalesOrderHeader'; 
SET @table3 = N'SalesOrderDetail'; 
SET @salesschema = N'Sales';
SET @hrschema = N'HumanResources';
SET @filterclause = N'Employee.LoginID = HOST_NAME()';

-- Drop the merge join filter between SalesOrderHeader and SalesOrderDetail.
EXEC sp_dropmergefilter 
  @publication = @publication, 
  @article = @table3, 
  @filtername = N'SalesOrderDetail_SalesOrderHeader', 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Drops the merge join filter between Employee and SalesOrderHeader.
EXEC sp_dropmergefilter 
  @publication = @publication, 
  @article = @table2, 
  @filtername = N'SalesOrderHeader_Employee', 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Drops the article for the SalesOrderDetail table.
EXEC sp_dropmergearticle 
  @publication = @publication, 
  @article = @table3,
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Drops the article for the SalesOrderHeader table.
EXEC sp_dropmergearticle 
  @publication = @publication, 
  @article = @table2, 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Drops the article for the Employee table.
EXEC sp_dropmergearticle 
  @publication = @publication, 
  @article = @table1,
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;
GO

DECLARE @publication AS sysname;
DECLARE @article1 AS sysname;
DECLARE @article2 AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @article1 = N'SalesOrderDetail'; 
SET @article2 = N'SalesOrderHeader'; 

-- Remove articles from a merge publication.
USE [AdventureWorks2008R2]
EXEC sp_dropmergearticle 
  @publication = @publication, 
  @article = @article1,
  @force_invalidate_snapshot = 1;
EXEC sp_dropmergearticle 
  @publication = @publication, 
  @article = @article2,
  @force_invalidate_snapshot = 1;
GO