sp_adddistributor (Transact-SQL)

sys.sysservers 資料表中建立一個項目 (如果沒有的話),將伺服器項目標示為散發者,再儲存屬性資訊。這個預存程序執行於 master 資料庫的散發者端,以便登錄伺服器,並將伺服器標示為散發者。如果是遠端散發者,它也會在 master 資料庫的發行者端執行,以登錄遠端散發者。

主題連結圖示Transact-SQL 語法慣例

語法

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

引數

  • [ @distributor=] 'distributor'
    這是散發伺服器名稱。distributorsysname,沒有預設值。只有在設定遠端散發者時,才使用這個參數。它會在 msdb..MSdistributor 資料表中,加入散發者屬性的項目。
  • [ @heartbeat_interval=] heartbeat_interval
    這是在未記錄進度訊息的情況下,代理程式所能執行的最大分鐘數。heartbeat_intervalint,預設值是 10 分鐘。系統會建立一項 SQL Server Agent 作業,依這個間隔來執行,以便檢查執行中之複寫代理程式的狀態。
  • [ @password=] 'password']
    這是 distributor_admin 登入的密碼。passwordsysname,預設值是 NULL。如果是 NULL 或空字串,就會將密碼重設為隨機值。當加入第一個遠端散發者時,必須設定密碼。distributor_admin 登入和 password 都是針對 distributor RPC 連接 (包括本機連接) 所用的連結伺服器項目來儲存。如果 distributor 在本機,distributor_admin 的密碼就會設為新值。如果是含遠端散發者的發行者,當在發行者端和散發者端執行 sp_adddistributor 時,必須指定相同的 password 值。sp_changedistributor_password 可用來變更散發者密碼。

    ms176028.security(zh-tw,SQL.90).gif安全性注意事項:
    可能的話,會在執行階段提示使用者輸入安全性認證。如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。
  • [ @from_scripting= ] from_scripting
    僅供內部使用。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_adddistributor 用於快照式複寫、交易式複寫和合併式複寫中。

權限

只有系統管理員 (sysadmin) 固定伺服器角色的成員,才能夠執行 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'AdventureWorks'; 

-- 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 AdventureWorks 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_changedistributor_property (Transact-SQL)
sp_dropdistributor (Transact-SQL)
sp_helpdistributor (Transact-SQL)
系統預存程序 (Transact-SQL)

其他資源

How to: Configure Publishing and Distribution (Replication Transact-SQL Programming)
設定散發

說明及資訊

取得 SQL Server 2005 協助