sp_adddistributiondb (języka Transact-SQL)

Tworzy nową baza danych dystrybucji i instaluje schemat dystrybutora.baza danych dystrybucji przechowuje procedur, schematu i metadane używane w replikacja.Ta procedura składowana jest wykonywany na dystrybutora na baza danych master w celu utworzenia baza danych dystrybucji i zainstalować niezbędne tabele i procedur przechowywanych, wymagane w celu umożliwienia dystrybucji replikacja.

Ikona łącza do tematuKonwencje składni Transact-SQL

Składnia

sp_adddistributiondb [ @database= ] 'database' 
    [ , [ @data_folder= ] 'data_folder' ] 
    [ , [ @data_file= ] 'data_file' ] 
    [ , [ @data_file_size= ] data_file_size ] 
    [ , [ @log_folder= ] 'log_folder' ] 
    [ , [ @log_file= ] 'log_file' ] 
    [ , [ @log_file_size= ] log_file_size ] 
    [ , [ @min_distretention= ] min_distretention ] 
    [ , [ @max_distretention= ] max_distretention ] 
    [ , [ @history_retention= ] history_retention ] 
    [ , [ @security_mode= ] security_mode ] 
    [ , [ @login= ] 'login' ] 
    [ , [ @password= ] 'password' ] 
    [ , [ @createmode= ] createmode ]
    [ , [ @from_scripting = ] from_scripting ]

Argumenty

  • [ @database=] database'
    Is the name of the distribution database to be created.database is sysname, with no default.Jeśli określona baza danych już istnieje i nie jest już oznaczona jako baza danych dystrybucji, następnie zainstalowane obiekty, niezbędne do umożliwienia dystrybucji i bazy danych jest oznaczony jako baza danych dystrybucji.Jeśli określona baza danych jest już włączony jako baza danych dystrybucji, zwracany jest błąd.

  • [ @ data_folder = **'**data_folder'
    Is the name of the directory used to store the distribution database data file.data_folder is nvarchar(255), with a default of NULL.If NULL, the data directory for that instance of Microsoft SQL Server is used, for example, C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data.

  • [ @ data_file = 'data_file"
    Is the name of the database file.data_file is nvarchar(255), with a default of database.Jeśli ma wartość NULL, procedura składowana konstruuje nazwę pliku przy użyciu nazwy bazy danych.

  • [ @ data_file_size = data_file_size
    Is the initial data file size in megabytes (MB).data_file_size is int, with a default of 5MB.

  • [ @ log_folder = 'log_folder"
    Is the name of the directory for the database log file.log_folder is nvarchar(255), with a default of NULL.Jeśli ma wartość NULL, katalog danych dla tego wystąpienie SQL Server jest używany (na przykład C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data).

  • [ @ plik_dziennika = 'log_file"
    Is the name of the log file.log_file is nvarchar(255), with a default of NULL.Jeśli ma wartość NULL, procedura składowana konstruuje nazwę pliku przy użyciu nazwy bazy danych.

  • [ @ log_file_size = log_file_size
    Is the initial log file size in megabytes (MB).log_file_size is int, with a default of 0 MB, which means the file size is created using the smallest log file size allowed by SQL Server.

  • [ @ min_distretention = min_distretention
    Is the minimum retention period, in hours, before transactions are deleted from the distribution database.min_distretention is int, with a default of 0 hours.

  • [ @ max_distretention = max_distretention
    Is the maximum retention period, in hours, before transactions are deleted.max_distretention is int, with a default of 72 hours.Subskrypcje, które nie otrzymały replikowane poleceń, które są starsze niż maksymalna okres przechowywania dystrybucji są oznaczone jako nieaktywne i trzeba należy ponownie zainicjować.RAISERROR 21011 jest wydawany dla subskrypcja nieaktywne.Wartość 0 oznacza, że replikowane transakcje nie są przechowywane w baza danych dystrybucji.

  • [ @ history_retention = history_retention
    Is the number of hours to retain history.history_retention is int, with a default of 48 hours.

  • [ @ security_mode = security_mode
    Is the security mode to use when connecting to the Distributor.security_mode is int, with a default of 1.0 Określa SQL Server uwierzytelniania; 1 określa zintegrowane uwierzytelnianie systemu Windows.

  • [ @ login = 'login"
    Nazwa logowania służy nawiązując do dystrybutora do utworzenia baza danych dystrybucji.This is required if security_mode is set to 0.login is sysname, with a default of NULL.

  • [ @ hasło = 'password"
    Hasło jest używany przy łączeniu się z dystrybutorem.Jest to wymagane, jeśli security_mode jest zestaw do 0. password jest sysname, domyślna wartość NULL.

  • [ @ createmode = createmode
    createmodejest int, domyślna wartość 1, i może być jedną z następujących wartości.

    Wartość

    Opis

    0

    Określone tylko w celach informacyjnych. Nieobsługiwane. Przyszła zgodność nie jest gwarantowana.

    1 (domyślnie)

    Tworzenie bazy danych lub użyj istniejącej bazy danych, a następnie zastosować instdist.sql pliku, aby utworzyć obiekty replikacja baza danych dystrybucji.

    2

    Określone tylko w celach informacyjnych. Nieobsługiwane. Przyszła zgodność nie jest gwarantowana.

  • [ @ from_scripting = from_scripting
    Określone tylko w celach informacyjnych. Nieobsługiwane. Przyszła zgodność nie jest gwarantowana. 

Wartości kodów powrotnych

0 (sukces) lub 1 (błąd)

Uwagi

sp_adddistributiondb jest używana we wszystkich typach replikacja.Jednak tej procedura składowana uruchamia tylko u dystrybutor.

Należy skonfigurować dystrybutor, wykonując sp_adddistributor przed wykonaniem sp_adddistributiondb.

Uruchom sp_adddistributor przed na uruchomiony sp_adddistributiondb.

Przykład

-- 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 

Uprawnienia

Tylko członkowie sysadmin stała rola serwera można wykonać sp_adddistributiondb.