sp_dropsubscription (Transact-SQL)

適用於:SQL ServerAzure SQL 受控執行個體

卸除發行者上特定發行項、發行集或一組訂閱的訂閱。 這個預存程式會在發行集資料庫的發行者端執行。

Transact-SQL 語法慣例

語法

sp_dropsubscription
    [ [ @publication = ] N'publication' ]
    [ , [ @article = ] N'article' ]
    , [ @subscriber = ] N'subscriber'
    [ , [ @destination_db = ] N'destination_db' ]
    [ , [ @ignore_distributor = ] ignore_distributor ]
    [ , [ @reserved = ] N'reserved' ]
    [ , [ @publisher = ] N'publisher' ]
[ ; ]

引數

[ @publication = ] N'publication'

相關聯發行集的名稱。 @publication為 sysname,預設值為 NULL。 如果 all為,則會取消指定訂閱者的所有發行集的所有訂閱。 publication 是必要參數。

[ @article = ] N'article'

發行項的名稱。 @article為 sysname,預設值為 NULL。 如果 all為,則會卸除每個指定發行集和訂閱者的所有發行項訂閱。 用於 all 允許立即更新的發行集。

[ @subscriber = ] N'subscriber'

將卸除其訂閱的訂閱者名稱。 @subscriber為 sysname,沒有預設值。 如果 all為,則會卸除所有訂閱者的所有訂閱。

[ @destination_db = ] N'destination_db'

目的地資料庫的名稱。 @destination_db為 sysname,預設值為 NULL。 如果 NULL為,則會卸除該訂閱者的所有訂閱。

[ @ignore_distributor = ] ignore_distributor

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

[ @reserved = ] N'reserved'

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

[ @publisher = ] N'publisher'

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

傳回碼值

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

備註

sp_dropsubscription 用於快照式和事務複製。

如果您在立即同步發行集的發行項上卸除訂閱,除非您卸除發行集中所有發行項上的訂閱,並同時將它們全部新增回來,否則您無法將其加回。

範例

-- 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 [AdventureWorks2022]
EXEC sp_dropsubscription 
  @publication = @publication, 
  @article = N'all',
  @subscriber = @subscriber;
GO

權限

只有系統管理員固定伺服器角色、db_owner固定資料庫角色或建立訂閱的使用者才能執行 sp_dropsubscription