sp_dropdistributor (Transact-SQL)

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

卸載散發者。 此預存程式會在散發資料庫以外的任何資料庫的散發者端執行。

Transact-SQL 語法慣例

語法

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

引數

[ @no_checks = ] no_checks

指出是否要在卸除散發者之前檢查相依物件。 @no_checks為 bit,預設值為 0

  • 如果 0為 , sp_dropdistributor 則檢查以確定除了散發者之外,所有發佈和散發物件都已卸除。

  • 如果 1為 , sp_dropdistributor 請先卸除所有發佈和散發物件,再卸載散發者。

[ @ignore_distributor = ] ignore_distributor

指出是否執行這個預存程式,而不連接到散發者。 @ignore_distributor為 bit,預設值為 0

  • 如果 0為 , sp_dropdistributor 則連接到散發者並移除所有復寫物件。 如果 sp_dropdistributor 無法連線到散發者,預存程式就會失敗。

  • 如果 1為 ,則不會對散發者建立連線,而且不會移除復寫物件。 如果散發者正在卸載或永久脫機,則會使用此選項。 在散發者端移除此發行者的物件,直到未來重新安裝散發者為止。

傳回碼值

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

備註

sp_dropdistributor 用於所有類型的複寫。

如果伺服器上存在其他發行者或散發物件,除非@no_checks設定為 1sp_dropdistributor否則會失敗。

執行 卸除散發資料庫之後,必須執行 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

權限

只有系統管理員固定伺服器角色的成員才能執行 sp_dropdistributor