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取消指定订阅服务器的所有发布的所有订阅。 发布 是必需参数。

[ @article = ] N'article'

项目的名称。 @article为 sysname,默认值为 NULL. 如果 all删除每个指定发布和订阅服务器的所有项目订阅。 用于 all 允许立即更新的发布。

[ @subscriber = ] N'subscriber'

将删除其订阅的订阅服务器的名称。 @subscribersysname,无默认值。 如果 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用于快照和事务副本 (replica)。

如果在立即同步发布的项目上删除订阅,则无法将其添加回,除非删除发布中所有文章的订阅,并将它们全部添加回一次。

示例

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

权限

只有 sysadmin 固定服务器角色、db_owner固定数据库角色或创建订阅的用户才能执行sp_dropsubscription