sp_dropdistributiondb (Transact-SQL)

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

卸除散發資料庫。 如果資料庫未使用實體檔案,則卸除資料庫所使用的實體檔案。 此預存程式會在任何資料庫的散發者端執行。

Transact-SQL 語法慣例

語法

sp_dropdistributiondb
    [ @database = ] N'database'
    [ , [ @former_ag_secondary = ] former_ag_secondary ]
[ ; ]

引數

[ @database = ] N'database'

要卸除的資料庫。 @database為 sysname,沒有預設值。

[ @former_ag_secondary = ] former_ag_secondary

指定此節點是否先前是散發資料庫可用性群組的一部分。 @former_ag_secondary為 int,預設值為 0

傳回碼值

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

備註

sp_dropdistributiondb 用於所有類型的複寫。

執行 之前,必須先執行這個預存程式,才能卸 sp_dropdistributor除散發者。

sp_dropdistributiondb 如果散發資料庫存在,也會移除散發資料庫的佇列讀取器代理程序作業。

若要停用散發,散發資料庫必須處於在線狀態。 如果散發資料庫存在資料庫快照集,必須先卸除它,才能停用散發。 資料庫快照集是資料庫的唯讀脫機複本,與復寫快照集無關。 如需詳細資訊,請參閱資料庫快照集(SQL Server)。

範例

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