sp_adddistributor (Transact-SQL)

sys.sysservers 表中创建一个条目(如果该表中没有条目),将服务器条目标记为分发服务器,并存储属性信息。此存储过程在分发服务器上对主数据库执行以注册服务器,并将其标记为分发服务器。如果是远程分发服务器,此存储过程还在发布服务器上对主数据库执行以注册远程分发服务器。

主题链接图标Transact-SQL 语法约定

语法

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

参数

  • [ @distributor= ] 'distributor'
    分发服务器名称。distributor 的数据类型为 sysname,没有默认值。只有在设置远程分发服务器时才使用此参数。它在 msdb..MSdistributor 表中添加分发服务器属性的条目。
  • [ @heartbeat_interval=] heartbeat_interval
    代理在不记录进度消息的情况下可以运行的最长分钟数。heartbeat_interval 的数据类型为 int,默认值为 10 分钟。创建按此间隔运行的 SQL Server 代理作业,以检查正在运行的复制代理的状态。
  • [ @password=] 'password']
    distributor_admin 登录名的密码。password 的数据类型为 sysname,默认值为 NULL。如果为 NULL 或空字符串,则密码重置为随机值。必须在添加第一个远程分发服务器时配置密码。distributor_admin 登录名和 password 是为用于 distributor RPC 连接(包括本地连接)的链接服务器条目存储的。如果 distributor 为本地分发服务器,则 distributor_admin 的密码设置为新值。对于具有远程分发服务器的发布服务器,必须在 sp_adddistributor 在发布服务器和分发服务器上同时执行时指定同一个 password 值。sp_changedistributor_password 可用于更改分发服务器密码。

    ms176028.security(zh-cn,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 帮助