sp_dropdistributor (Transact-SQL)

适用于:SQL ServerAzure SQL 托管实例

卸载分发服务器。 此存储过程在分发服务器上除分发数据库之外的任何数据库中执行。

Transact-SQL 语法约定

语法

sp_dropdistributor
    [ [ @no_checks = ] no_checks ]
    [ , [ @ignore_distributor = ] ignore_distributor ]
[ ; ]

参数

[ @no_checks = ] no_检查s

指示在删除分发服务器之前是否检查有无依赖对象。 @no_检查为,默认值为 0.

  • 如果0sp_dropdistributor 检查以确保除了分发服务器之外,还删除了所有发布和分发对象。

  • 如果 1sp_dropdistributor 在卸载分发服务器之前删除所有发布和分发对象。

[ @ignore_distributor = ] ignore_distributor

指示是否在未连接到分发服务器的情况下执行此存储过程。 @ignore_distributor,默认值为 0.

  • 如果0连接到sp_dropdistributor分发服务器并删除所有副本 (replica)对象。 如果 sp_dropdistributor 无法连接到分发服务器,则存储过程会失败。

  • 如果没有1与分发服务器建立连接,并且不会删除副本 (replica)tion 对象。 如果分发服务器正在卸载或永久脱机,则使用此选项。 在分发服务器上重新安装分发服务器之前,不会删除此发布服务器的对象。

返回代码值

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

注解

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

如果服务器上存在其他发布服务器或分发对象,sp_dropdistributor除非@no_检查设置为 1

通过执行 sp_dropdistributiondb删除分发数据库后,必须执行此存储过程。

示例

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