sp_adddistpublisher (Transact-SQL)
適用対象: SQL ServerAzure SQL Managed Instance
指定されたディストリビューション データベースを使用するように、パブリッシャーを構成します。 このストアド プロシージャは、任意のデータベースのディストリビューターで実行されます。 ストアド プロシージャ sp_adddistributor (Transact-SQL) と sp_adddistributiondb (Transact-SQL) は、このストアド プロシージャを使用する前に実行しておく必要があります。
構文
sp_adddistpublisher
[ @publisher = ] N'publisher'
, [ @distribution_db = ] N'distribution_db'
[ , [ @security_mode = ] security_mode ]
[ , [ @login = ] N'login' ]
[ , [ @password = ] N'password' ]
[ , [ @working_directory = ] N'working_directory' ]
[ , [ @trusted = ] N'trusted' ]
[ , [ @encrypted_password = ] encrypted_password ]
[ , [ @thirdparty_flag = ] thirdparty_flag ]
[ , [ @publisher_type = ] N'publisher_type' ]
[ , [ @storage_connection_string = ] N'storage_connection_string' ]
[ ; ]
引数
[ @publisher = ] N'publisher'
パブリッシャー名。 @publisherは sysname で、既定値はありません。
Note
サーバー名は次のように <Hostname>,<PortNumber>
指定できます。 SQL Server がカスタム ポートを使用して Linux または Windows にデプロイされ、ブラウザー サービスが無効になっている場合に、接続のポート番号を指定します。 リモート ディストリビューターのカスタム ポート番号の使用は、SQL Server 2019 (15.x) 以降のバージョンに適用されます。
[ @distribution_db = ] N'distribution_db'
ディストリビューション データベースの名前。 @distribution_dbは sysname で、既定値はありません。 このパラメーターは、レプリケーション エージェントがパブリッシャーに接続するために使用します。
[ @security_mode = ] security_mode
実装されたセキュリティ モード。 このパラメーターは、キュー更新サブスクリプションまたは SQL Server 以外のパブリッシャーを使用してパブリッシャーに接続するために、レプリケーション エージェントによってのみ使用されます。 @security_modeは int であり、これらの値のいずれかになります。
Value | 説明 |
---|---|
0 |
ディストリビューターのレプリケーション エージェントは、SQL Server 認証を使用してパブリッシャーに接続します。 |
1 (既定) |
ディストリビューター側のレプリケーション エージェントは Windows 認証を使用してパブリッシャーに接続します。 |
[ @login = ] N'login'
ログイン。 このパラメーターは、security_modeが a0/> の場合に必要です0
。 @loginは sysname で、既定値は NULL
. このパラメーターは、レプリケーション エージェントがパブリッシャーに接続するために使用します。
[ @password = ] N'password'
パスワード。 @passwordは sysname で、既定値は NULL
. このパラメーターは、レプリケーション エージェントがパブリッシャーに接続するために使用します。
重要
空白のパスワードを使用しないでください。 強力なパスワードを使用してください。
[ @working_directory = ] N'working_directory'
パブリケーションのデータ ファイルとスキーマ ファイルを格納するために使用される作業ディレクトリの名前。 @working_directoryは nvarchar(255) で、SQL ReplData
Server のこのインスタンスの既定のフォルダーです。 たとえば、C:\Program Files\Microsoft SQL Server\MSSQL\MSSQL.1\ReplData
のようにします。 名前は UNC 形式で指定する必要があります。
Azure SQL Database の場合は、次を使用します \\<storage_account>.file.core.windows.net\<share>
。
[ @trusted = ] N'trusted'
@trustedは非推奨であり、下位互換性のみを目的として提供されています。 @trustedは nvarchar(5) で、既定値は false
. このパラメーターを設定すると、 false
エラーが発生します。
[ @encrypted_password = ] encrypted_password
このパラメーターの設定はサポートされなくなりました。 @encrypted_passwordはビットで、既定値は 0
. このパラメーターを設定すると 1
、エラーが発生します。
[ @thirdparty_flag = ] thirdparty_flag
パブリッシャーが SQL Server の場合を指定します。 @thirdparty_flagビットであり、次のいずれかの値を指定できます。
Value | 説明 |
---|---|
0 (既定値) |
SQL Server データベース。 |
1 |
SQL Server 以外のデータベース。 |
[ @publisher_type = ] N'publisher_type'
パブリッシャーが SQL Server でない場合のパブリッシャーの種類を指定します。 @publisher_typeは sysname であり、次のいずれかの値を指定できます。
Value | 説明 |
---|---|
MSSQLSERVER (既定値) |
SQL Server パブリッシャーを指定します。 |
ORACLE |
標準の Oracle パブリッシャーを指定します。 |
ORACLE GATEWAY |
Oracle ゲートウェイ パブリッシャーを指定します。 |
Oracle パブリッシャーと Oracle ゲートウェイ パブリッシャーの違いの詳細については、「Oracle パブリッシャーの構成」を参照してください。
[ @storage_connection_string = ] N'storage_connection_string'
Azure SQL Database に必要です。 @storage_connection_stringは nvarchar(255) で、既定値は NULL
. Azure portal の [ストレージ > 設定] でアクセス キーを使用します。
Note
Azure SQL Database のパブリッシャー データベースとディストリビューター データベースには、SQL Managed Instance が必要 です。 詳細については、「Azure SQL Database を使用したレプリケーション」を参照してください。
リターン コードの値
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'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_adddistpublisher
できます。
関連するコンテンツ
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示