sp_dropmergearticle (Transact-SQL)

適用於:SQL Server

從合併式發行集移除發行項。 這個預存程式會在發行集資料庫的發行者端執行。

Transact-SQL 語法慣例

語法

sp_dropmergearticle
    [ @publication = ] N'publication'
    , [ @article = ] N'article'
    [ , [ @ignore_distributor = ] ignore_distributor ]
    [ , [ @reserved = ] reserved ]
    [ , [ @force_invalidate_snapshot = ] force_invalidate_snapshot ]
    [ , [ @force_reinit_subscription = ] force_reinit_subscription ]
    [ , [ @ignore_merge_metadata = ] ignore_merge_metadata ]
[ ; ]

引數

[ @publication = ] N'publication'

要卸除發行項的發行集名稱。 @publication為 sysname,沒有預設值。

[ @article = ] N'article'

要從指定發行集卸除之發行項的名稱。 @article為 sysname,沒有預設值。 如果 all為 ,則會移除指定之合併式發行集中的所有現有發行項。 即使 @articleall,發行集仍必須與發行項分開卸除。

[ @ignore_distributor = ] ignore_distributor

指出是否執行這個預存程式,而不連接到散發者。 @ignore_distributor為 bit,預設值為 0

[ @reserved = ] 保留

保留供未來使用。 @reserved為 bit,預設值為 0

[ @force_invalidate_snapshot = ] force_invalidate_snapshot

啟用或停用快照集失效的能力。 @force_invalidate_snapshot為 bit,預設值為 0

  • 0 指定合併發行項的變更不會造成快照集無效。

  • 1 表示合併發行項的變更可能會導致快照集無效,如果發生這種情況,則 值 1 會授與新快照集發生的許可權。

[ @force_reinit_subscription = ] force_reinit_subscription

確認卸除發行項需要重新初始化現有的訂用帳戶。 @force_reinit_subscription為 bit,預設值為 0

  • 0 指定卸除發行項不會使訂閱重新初始化。

  • 1 表示卸除發行項會導致重新初始化現有的訂閱,並授與重新初始化訂閱的許可權。

[ @ignore_merge_metadata = ] ignore_merge_metadata

僅供參考之用。 不支援。 我們無法保證未來的相容性。

傳回碼值

0 (成功)或 1 (失敗)。

備註

sp_dropmergearticle 用於合併式複寫。 如需卸除發行項的詳細資訊,請參閱 將發行項新增至現有發行集和卸除發行項。

執行 sp_dropmergearticle 以從發行集卸除發行項並不會從發行集資料庫移除物件,也不會從訂閱資料庫移除對應的物件。 必要時,請使用 DROP <object> 來手動移除這些物件。

權限

只有系統管理員固定伺服器角色或db_owner固定資料庫角色的成員才能執行 sp_dropmergearticle

範例

本文需要AdventureWorks2022範例資料庫,您可以從 Microsoft SQL Server 範例和社群專案首頁下載

A. 從合併式發行集移除發行項

USE [AdventureWorks2022];
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';

EXEC sp_dropmergearticle @publication = @publication,
    @article = @article1,
    @force_invalidate_snapshot = 1;

EXEC sp_dropmergearticle @publication = @publication,
    @article = @article2,
    @force_invalidate_snapshot = 1;
GO
USE [AdventureWorks2022];
GO

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;

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

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

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

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