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_checks

指定是否檢查發行者是否已 sp_dropdistpublisher 將伺服器卸載為散發者。 @no_checks為 bit,預設值為 0

  • 如果 0為 ,復寫會確認遠端發行者已將本地伺服器卸載為散發者。 如果發行者是本機,複寫會確認本地伺服器上沒有剩餘的發行集或散發物件。

  • 如果 1為 ,即使無法連線到遠端發行者,也會卸除與散發發行者相關聯的所有復寫物件。 執行此動作之後,遠端發行者必須使用 搭配 sp_dropdistributor@ignore_distributor = 1卸載複寫。

[ @ignore_distributor = ] ignore_distributor

指定移除發行者時,散發物件是否留在散發者端。 @ignore_distributor位,而且可以是下列其中一個值:

  • 1= 屬於@publisher散發物件會保留在散發者端。
  • 0= 散發者端會清除@publisher的散發物件

傳回碼值

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

備註

sp_dropdistpublisher 用於所有類型的複寫。

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

權限

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