sp_dropdistpublisher (Transact-SQL)

适用于:SQL ServerAzure SQL 托管实例

删除分发发布服务器。 此存储过程在分发服务器上的任何数据库中执行。

Transact-SQL 语法约定

语法

sp_dropdistpublisher
    [ @publisher = ] N'publisher'
    [ , [ @no_checks = ] no_checks ]
    [ , [ @ignore_distributor = ] ignore_distributor ]
[ ; ]

参数

[ @publisher = ] N'publisher'

要删除的发布服务器。 @publisher为 sysname,无默认值。

注意

SQL Server 2019(15.x)中引入了 SQL Server 发布服务器的自定义端口。 如果 SQL Server 发布服务器配置了自定义端口,则在分发服务器上删除此类发布服务器时,请提供发布服务器名称而不是 <Hostname>,<PortNumber>

[ @no_checks = ] no_检查s

指定发布服务器是否已sp_dropdistpublisher将服务器卸载为分发服务器检查。 @no_检查为,默认值为 0.

  • 如果0,副本 (replica)tion 会验证远程发布服务器是否已将本地服务器卸载为分发服务器。 如果发布服务器是本地服务器,则复制将验证没有发布对象或分发对象保留在本地服务器上。

  • 如果1删除与分发发布服务器关联的所有副本 (replica)tion 对象,即使无法访问远程发布服务器也是如此。 执行此操作后,远程发布服务器必须使用sp_dropdistributor卸载副本 (replica)。@ignore_distributor = 1

[ @ignore_distributor = ] ignore_distributor

指定删除发布服务器时是否将分发对象保留在分发服务器中。 @ignore_distributor,可以是以下值之一:

  • 1= 属于@publisher分发对象保留在分发服务器上。
  • 0= 分发服务器上清理@publisher的分布对象

返回代码值

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

备注

sp_dropdistpublisher用于所有类型的副本 (replica)。

删除 Oracle 发布服务器时,如果无法删除发布服务器, sp_dropdistpublisher 则返回错误并删除发布服务器的分发服务器对象。

示例

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

-- Disable publishing and distribution.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB as sysname;
SET @distributionDB = N'distribution';
SET @publisher = $(DistPubServer);
SET @publicationDB = N'AdventureWorks2022';

-- Disable the publication database.
USE [AdventureWorks2022]
EXEC sp_removedbreplication @publicationDB;

-- Remove the registration of the local Publisher at the Distributor.
USE master
EXEC sp_dropdistpublisher @publisher;

-- Delete the distribution database.
EXEC sp_dropdistributiondb @distributionDB;

-- Remove the local server as a Distributor.
EXEC sp_dropdistributor;
GO

权限

只有 sysadmin 固定服务器角色的成员才能执行sp_dropdistpublisher