sp_droppullsubscription (Transact-SQL)

适用于:SQL ServerAzure SQL 托管实例

在订阅服务器的当前数据库中删除订阅。 此存储过程在订阅服务器上对请求订阅数据库执行。

Transact-SQL 语法约定

语法

sp_droppullsubscription
    [ @publisher = ] N'publisher'
    [ , [ @publisher_db = ] N'publisher_db' ]
    , [ @publication = ] N'publication'
    [ , [ @reserved = ] reserved ]
    [ , [ @from_backup = ] from_backup ]
[ ; ]

参数

[ @publisher = ] N'publisher'

远程服务器名称。 @publisher为 sysname,无默认值。 如果 all,则会在所有发布服务器上删除订阅。

[ @publisher_db = ] N'publisher_db'

发布服务器数据库的名称。 @publisher_db为 sysname,默认值为 NULL. all 表示所有发布服务器数据库。

[ @publication = ] N'publication'

发布名。 @publicationsysname,无默认值。 如果 all为订阅,则会将订阅删除到所有发布。

[ @reserved = ] reserved

标识为仅供参考。 不支持。 不保证以后的兼容性。

[ @from_backup = ] from_backup

标识为仅供参考。 不支持。 不保证以后的兼容性。

返回代码值

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

备注

sp_droppullsubscription用于快照 副本 (replica)和事务副本 (replica)。

sp_droppullsubscription删除 MS副本 (replica)tion_subscriptions (Transact-SQL) 表中的相应行以及订阅服务器上的相应分发服务器代理。 如果 MS副本 (replica)tion_subscriptions (Transact-SQL)没有留下任何行,则会删除该表。

示例

-- 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 is the batch executed at the Subscriber to drop 
-- a pull subscription to a transactional publication.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB     AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2022';

USE [AdventureWorks2022Replica]
EXEC sp_droppullsubscription 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication;
GO

权限

只有 sysadmin 固定服务器角色的成员或创建请求订阅的用户才能执行sp_droppullsubscription仅当创建请求订阅的用户属于此角色时,才能执行sp_droppullsubscriptiondb_owner固定数据库角色。