パブリッシャとディストリビュータのプロパティを表示および変更する方法 (レプリケーション Transact-SQL プログラミング)

パブリッシャとディストリビュータのプロパティは、プログラムからレプリケーション ストアド プロシージャを使用して表示できます。

ディストリビュータとディストリビューション データベースのプロパティを表示するには

  1. sp_helpdistributor を実行すると、ディストリビュータ、ディストリビューション データベース、作業ディレクトリに関する情報が返されます。

  2. sp_helpdistributiondb を実行すると、指定されたディストリビューション データベースのプロパティが返されます。

ディストリビュータとディストリビューション データベースのプロパティを変更するには

  1. ディストリビュータのプロパティを変更するには、ディストリビュータで sp_changedistributor_property を実行します。

  2. ディストリビューション データベースのプロパティを変更するには、ディストリビュータで sp_changedistributiondb を実行します。

  3. ディストリビュータのパスワードを変更するには、ディストリビュータで sp_changedistributor_password を実行します。

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

    可能であれば、実行時にユーザーの資格情報の入力を求めるメッセージを表示します。資格証明をスクリプト ファイルに保存するのは避けてください。

  4. ディストリビュータを使用しているパブリッシャのプロパティを変更するには、ディストリビュータで sp_changedistpublisher を実行します。

使用例

次の例では、Transact-SQL スクリプトによってディストリビュータおよびディストリビューション データベースに関する情報を返します。

-- View information about the Distributor, distribution database, 
-- working directory, and SQL Server Agent user account. 
USE master
EXEC sp_helpdistributor;
GO
-- View information about the specified distribution database. 
USE distribution
EXEC sp_helpdistributiondb;
GO

次の例では、ディストリビュータの保有期間、ディストリビュータへの接続時に使用されるパスワード、およびディストリビュータが各種レプリケーション エージェントの状態を確認する間隔 (ハートビート間隔) を変更します。

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

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

-- Change the heartbeat interval at the Distributor to 5 minutes. 
USE master 
exec sp_changedistributor_property 
    @property = N'heartbeat_interval', 
    @value = 5;
GO
DECLARE @distributionDB AS sysname;
SET @distributionDB = N'distribution';

-- Change the history retention period to 24 hours and the
-- maximum retention period to 48 hours.  
USE distribution
EXEC sp_changedistributiondb @distributionDB, N'history_retention', 24
EXEC sp_changedistributiondb @distributionDB, N'max_distretention', 48
GO 
-- Change the password on the Distributor. 
-- To avoid storing the password in the script file, the value is passed 
-- into SQLCMD as a scripting variable. 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".
USE master
EXEC sp_changedistributor_password $(Password)
GO