sp_adddistpublisher (Transact-SQL)

指定されたディストリビューション データベースを使用するように、パブリッシャを構成します。このストアド プロシージャは、任意のデータベース上のディストリビュータ側で実行されます。このストアド プロシージャを使用する前に、sp_adddistributor (Transact-SQL) ストアド プロシージャと sp_adddistributiondb (Transact-SQL) ストアド プロシージャを実行しておく必要がある点に注意してください。

トピック リンク アイコンTransact-SQL 構文表記規則

構文

sp_adddistpublisher [ @publisher= ] 'publisher' 
        , [ @distribution_db= ] 'distribution_db' 
    [ , [ @security_mode= ] security_mode ] 
    [ , [ @login= ] 'login' ] 
    [ , [ @password= ] 'password' ] 
    [ , [ @working_directory= ] 'working_directory' ] 
    [ , [ @trusted= ] 'trusted' ] 
    [ , [ @encrypted_password= ] encrypted_password ] 
    [ , [ @thirdparty_flag = ] thirdparty_flag ]
    [ , [ @publisher_type = ] 'publisher_type' ]

引数

  • [ @publisher=] 'publisher'
    パブリッシャ名を指定します。publisher のデータ型は sysname で、既定値はありません。

  • [ @distribution_db=] 'distribution_db'
    ディストリビューション データベースの名前を指定します。distributor_db のデータ型は sysname で、既定値はありません。このパラメータは、レプリケーション エージェントがパブリッシャに接続するために使用します。

  • [ @security_mode=] security_mode
    実装されているセキュリティ モードを指定します。このパラメータは、キュー更新サブスクリプションのパブリッシャに接続する場合、または SQL Server 以外のパブリッシャを使用する場合に、レプリケーション エージェントのみによって使用されます。security_mode のデータ型は int で、次のいずれかの値を指定できます。

    説明

    0

    ディストリビュータ側のレプリケーション エージェントは SQL Server 認証を使用してパブリッシャに接続します。

    1 (既定値)

    ディストリビュータ側のレプリケーション エージェントは Windows 認証を使用してパブリッシャに接続します。

  • [ @login=] 'login'
    ログインを指定します。このパラメータは、security_mode0 の場合に必要です。login のデータ型は sysname で、既定値は NULL です。このパラメータは、レプリケーション エージェントがパブリッシャに接続するために使用します。

  • [ @password=] 'password']
    パスワードを指定します。password のデータ型は sysname で、既定値は NULL です。このパラメータは、レプリケーション エージェントがパブリッシャに接続するために使用します。

    セキュリティに関する注意セキュリティに関する注意

    パスワードは空白のままにしないでください。また複雑なパスワードを使用してください。

  • [ @working_directory=] 'working_directory'
    パブリケーション用のデータ ファイルとスキーマ ファイルの格納に使用する作業ディレクトリの名前を指定します。working_directory のデータ型は nvarchar(255) で、SQL Server のこのインスタンスに対する既定値は ReplData フォルダです。たとえば、"C:\Program Files\Microsoft SQL Server\MSSQL\MSSQ.1\ReplData" になります。名前は UNC 形式で指定する必要があります。

  • [ @trusted=] 'trusted'
    このパラメータは、非推奨であり、旧バージョンとの互換性のためにのみ提供されています。trusted のデータ型は nvarchar(5) で、これを false 以外に設定するとエラーになります。

  • [ @encrypted_password=] encrypted_password
    encrypted_password の設定は、サポートされなくなりました。この bit パラメータを 1 に設定すると、エラーになります。

  • [ @thirdparty_flag =] thirdparty_flag
    パブリッシャが SQL Server であるかどうかを指定します。thirdparty_flag のデータ型は bit で、次のいずれかの値を指定できます。

    説明

    0 (既定値)

    SQL Server データベース

    1

    SQL Server 以外のデータベース

  • [ @publisher_type= ] 'publisher_type'
    パブリッシャが SQL Server 以外の場合に、パブリッシャの種類を指定します。publisher_type のデータ型は sysname で、次のいずれかの値を指定できます。

    説明

    MSSQLSERVER 

    (既定値)

    SQL Server パブリッシャを指定します。

    ORACLE

    標準の Oracle パブリッシャを指定します。

    ORACLE GATEWAY

    Oracle ゲートウェイ パブリッシャを指定します。

    Oracle パブリッシャと Oracle ゲートウェイ パブリッシャの相違点の詳細については、「Oracle パブリッシャーの構成」を参照してください。

戻り値

0 (成功) または 1 (失敗)

説明

sp_adddistpublisher は、スナップショット レプリケーション、トランザクション レプリケーション、およびマージ レプリケーションで使用します。

使用例

-- 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'AdventureWorks2008R2'; 

-- 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 AdventureWorks2008R2 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_adddistpublisher を実行できるのは、sysadmin 固定サーバー ロールのメンバだけです。