sp_adddistributor (Transact-SQL)

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

在 sys.servers 數據表中建立專案(如果沒有的話),將伺服器項目標示為散發者,並儲存屬性資訊。 這個預存程式會在資料庫的散發者端 master 執行,以註冊伺服器並標示為散發者。 在遠端散發者的情況下,也會從 master 資料庫在發行者端執行,以註冊遠端散發者。

Transact-SQL 語法慣例

語法

sp_adddistributor
    [ @distributor = ] N'distributor'
    [ , [ @heartbeat_interval = ] heartbeat_interval ]
    [ , [ @password = ] N'password' ]
    [ , [ @from_scripting = ] from_scripting ]
[ ; ]

引數

[ @distributor = ] N'distributor'

散發伺服器名稱。 @distributor為 sysname,沒有預設值。 只有在設定遠端散發者時,才會使用此參數。 它會在數據表中 msdb..MSdistributor 新增散發者屬性的專案。

注意

伺服器名稱可以指定為 <Hostname>,<PortNumber>。 使用自定義埠在Linux或 Windows 上部署 SQL Server,並停用瀏覽器服務時,請指定連線的埠號碼。 遠端散發者的自定義埠號碼使用適用於 SQL Server 2019 (15.x) 和更新版本。

[ @heartbeat_interval = ] heartbeat_interval

代理程式可以執行的最大分鐘數,而不需要記錄進度訊息。 @heartbeat_interval為 int,預設值為10分鐘。 建立 SQL Server Agent 作業,此作業會在此間隔執行,以檢查正在執行的復寫代理程序狀態。

[ @password = ] N'password'

distributor_admin登入的密碼@password為 sysname,預設值為 NULL。 如果密碼為 NULL 或空字串, @password 會重設為隨機值。 新增第一個遠端散發者時,必須設定密碼。 distributor_admin登入和@password會儲存供散發者 RPC 連線使用的鏈接伺服器專案,包括本機連線。 如果散發者是本機,則distributor_admin的密碼會設定為新的值。 對於具有遠端散發者的發行者,在發行者和散發者端執行sp_adddistributor時,必須指定@password相同的值sp_changedistributor_password可用來變更散發者密碼。

重要

可能的話,會在執行階段提示使用者輸入安全性認證。 如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。

[ @from_scripting = ] from_scripting

@from_scripting為 bit,預設值為 0。 僅供參考之用。 不支援。 我們無法保證未來的相容性。

傳回碼值

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

備註

sp_adddistributor 用於快照式複寫、事務複製和合併式複寫。

範例

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

-- Install the Distributor and the distribution database.
DECLARE @distributor AS sysname;
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @directory AS nvarchar(500);
DECLARE @publicationDB AS sysname;
-- Specify the Distributor name.
SET @distributor = $(DistPubServer);
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);
-- Specify the replication working directory.
SET @directory = N'\\' + $(DistPubServer) + '\repldata';
-- Specify the publication database.
SET @publicationDB = N'AdventureWorks2022'; 

-- Install the server MYDISTPUB as a Distributor using the defaults,
-- including autogenerating the distributor password.
USE master
EXEC sp_adddistributor @distributor = @distributor;

-- Create a new distribution database using the defaults, including
-- using Windows Authentication.
USE master
EXEC sp_adddistributiondb @database = @distributionDB, 
    @security_mode = 1;
GO

-- Create a Publisher and enable AdventureWorks2022 for replication.
-- Add MYDISTPUB as a publisher with MYDISTPUB as a local distributor
-- and use Windows Authentication.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);

USE [distribution]
EXEC sp_adddistpublisher @publisher=@publisher, 
    @distribution_db=@distributionDB, 
    @security_mode = 1;
GO

權限

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