sp_adddistributor (Transact-SQL)

適用対象: SQL ServerAzure SQL Managed Instance

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 追加されます。

Note

サーバー名は次のように <Hostname>,<PortNumber>指定できます。 SQL Server がカスタム ポートを使用して Linux または Windows にデプロイされ、ブラウザー サービスが無効になっている場合に、接続のポート番号を指定します。 リモート ディストリビューターのカスタム ポート番号の使用は、SQL Server 2019 (15.x) 以降のバージョンに適用されます。

[ @heartbeat_interval = ] heartbeat_interval

進行状況メッセージをログに記録せずにエージェントが実行できる最大時間 (分)。 @heartbeat_intervalは int で、既定値は10分です。 実行中のレプリケーション エージェントの状態をチェックするために、この間隔で実行されるSQL Server エージェント ジョブが作成されます。

[ @password = ] N'password'

distributor_admin ログインのパスワード。 @passwordは sysname で、既定値は NULL. パスワードが空の場合NULL@passwordはランダムな値にリセットされます。 パスワードは最初のリモート ディストリビューターを追加するときに構成する必要があります。 distributor_adminログインと@passwordは、ローカル接続を含むディストリビューター RPC 接続に使用されるリンク サーバー エントリに格納されます。 ディストリビューターがローカルの場合、distributor_adminパスワードは新しい値に設定されます。 リモート ディストリビューターを使用するパブリッシャーの場合は、パブリッシャーとディストリビューターの両方で実行するときに、@passwordに同じ値sp_adddistributor指定する必要があります。 sp_changedistributor_passwordを使用してディストリビューターのパスワードを変更できます。

重要

可能であれば、実行時、ユーザーに対してセキュリティ資格情報の入力を要求します。 スクリプト ファイルに資格情報を格納する必要がある場合は、不正アクセスを防ぐために、ファイルを保護します。

[ @from_scripting = ] from_scripting

@from_scriptingはビットで、既定値は 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

アクセス許可

sysadmin 固定サーバー ロールのメンバーのみが実行sp_adddistributorできます。