sp_addpublication_snapshot (Transact-SQL)

更新日期: 2006 年 12 月 12 日

为指定的发布创建快照代理。 此存储过程在发布服务器的发布数据库中执行。

ms174958.security(zh-cn,SQL.90).gif安全说明:
使用远程分发服务器配置发布服务器时,为所有参数(包括 job_loginjob_password)提供的值都将作为纯文本发送到分发服务器。 在执行此存储过程之前,应当对发布服务器与其远程分发服务器之间的连接进行加密。 有关详细信息,请参阅加密与 SQL Server 的连接

主题链接图标Transact-SQL 语法约定

语法

sp_addpublication_snapshot [ @publication= ] 'publication'
    [ , [ @frequency_type= ] frequency_type ]
    [ , [ @frequency_interval= ] frequency_interval ]
    [ , [ @frequency_subday= ] frequency_subday ]
    [ , [ @frequency_subday_interval= ] frequency_subday_interval ]
    [ , [ @frequency_relative_interval= ] frequency_relative_interval ]
    [ , [ @frequency_recurrence_factor= ] frequency_recurrence_factor ]
    [ , [ @active_start_date= ] active_start_date ]
    [ , [ @active_end_date= ] active_end_date ]
    [ , [ @active_start_time_of_day= ] active_start_time_of_day ]
    [ , [ @active_end_time_of_day= ] active_end_time_of_day ]
    [ , [ @snapshot_job_name = ] 'snapshot_agent_name' ]
    [ , [ @publisher_security_mode = ] publisher_security_mode ]
    [ , [ @publisher_login = ] 'publisher_login' ]
    [ , [ @publisher_password = ] 'publisher_password' ] 
    [ , [ @job_login = ] 'job_login' ]
    [ , [ @job_password = ] 'job_password' ]
    [ , [ @publisher = ] 'publisher' ]

参数

  • [ @publication = ] 'publication'
    发布的名称。publication 的数据类型为 sysname,无默认值。
  • [ @frequency_type = ] frequency_type
    执行快照代理的频率。frequency_type 的数据类型为 int,可以是下列值之一。

    说明

    1

    一次。

    4(默认值)

    每天。

    8

    每周。

    16

    每月。

    32

    每月,相对于频率间隔。

    64

    SQL Server 代理启动时。

    128

    计算机空闲时运行。

  • [ @frequency_interval = ] frequency_interval
    应用于 frequency_type 所设频率的值。 frequency_interval 的数据类型为 int,并且可以为以下值之一。

    frequency_type 的值 frequency_interval 的影响

    1

    frequency_interval 未使用。

    4(默认值)

    每隔 frequency_interval 天,默认为每天。

    8

    frequency_interval 为下列一个或多个值(与 |(位或)(Transact-SQL) 逻辑运算符结合使用):

    1 = 星期日

    2 = 星期一

    4 = 星期二

    8 = 星期三

    16 = 星期四

    32 = 星期五

    64 = 星期六

    16

    在每月的 frequency_interval 日。

    32

    frequency_interval 是下列值之一:

    1 = 星期日

    2 = 星期一

    3 = 星期二

    4 = 星期三

    5 = 星期四

    6 = 星期五

    7 = 星期六

    8 = 天

    9 = 工作日

    10 = 休息日

    64

    frequency_interval 未使用。

    128

    frequency_interval 未使用。

  • [ @frequency_subday = ]frequency_subday
    freq_subday_interval 的单位。frequency_subday 的数据类型为 int,可以是下列值之一。

    说明

    1

    一次

    2

    4(默认值)

    分钟

    8

    小时

  • [ @frequency_subday_interval = ]frequency_subday_interval
    frequency_subday 的间隔。frequency_subday_interval 的数据类型为 int,默认值为 5,表示每隔 5 分钟。
  • [ @frequency_relative_interval = ]frequency_relative_interval
    快照代理运行的日期。frequency_relative_interval 的数据类型为 int,默认值为 1。
  • [ @frequency_recurrence_factor = ] frequency_recurrence_factor
    frequency_type 使用的重复因子。frequency_recurrence_factor 的数据类型为 int,默认值为 0。
  • [ @active_start_date = ] active_start_date
    第一次调度快照代理的日期,格式为 YYYYMMDD。active_start_date 的数据类型为 int,默认值为 0。
  • [ @active_end_date = ] active_end_date
    停止调度快照代理的日期,格式为 YYYYMMDD。active_end_date 的数据类型为 int,默认值为 99991231,表示 9999 年 12 月 31 日。
  • [ @active_start_time_of_day = ] active_start_time_of_day
    第一次调度快照代理的时间,格式为 HHMMSS。active_start_time_of_day 的数据类型为 int,默认值为 0。
  • [ @active_end_time_of_day = ] active_end_time_of_day
    停止调度快照代理的时间,格式为 HHMMSS。active_end_time_of_day 的数据类型为 int,默认值为 235959,表示 24 小时制的 11:59:59 P.M.。
  • [ @snapshot_job_name = ] 'snapshot_agent_name'
    现有快照代理作业的名称(如果正在使用现有作业)。snapshot_agent_name 的数据类型为 nvarchar(100),默认值为 NULL。 此参数只限内部使用,创建新发布时不应指定它。 如果指定了 snapshot_agent_name,则 job_loginjob_password 必须为 NULL。
  • [ @publisher_security_mode= ] publisher_security_mode
    连接发布服务器时代理使用的安全模式。publisher_security_mode 的数据类型为 smallint,默认值为 1。0 指定 SQL Server 身份验证,1 指定 Windows 身份验证。 对于非 SQL Server 发布服务器,必须将该值指定为 0
  • [ @publisher_login= ] 'publisher_login'
    连接到发布服务器时所使用的登录名。publisher_login 的数据类型为 sysname,默认值为 NULL。如果 publisher_security_mode0,则必须指定 publisher_login。 如果 publisher_login 为 NULL 并且 publisher_security_mode1,那么连接到发布服务器时将使用在 job_login 中指定的 Windows 帐户。
  • [ @publisher_password= ] 'publisher_password'
    连接到发布服务器时所用的密码。publisher_password 的数据类型为 sysname,默认值为 NULL。

    ms174958.security(zh-cn,SQL.90).gif安全说明:
    请不要将身份验证信息存储在脚本文件中。 在运行时应提供登录名和密码。
  • [ @job_login= ] 'job_login'
    运行代理所用的 Windows 帐户的登录名。job_login 的数据类型为 nvarchar(257),默认值为 NULL。 此 Windows 帐户总是用于与分发服务器建立代理连接。 创建新的快照代理作业时,必须提供此参数。
  • [ @job_password= ] 'job_password'
    用于运行代理的 Windows 帐户的密码。job_password 的数据类型为 sysname,无默认值。 创建新的快照代理作业时,必须提供此参数。

    ms174958.security(zh-cn,SQL.90).gif安全说明:
    请不要将身份验证信息存储在脚本文件中。 在运行时应提供登录名和密码。
  • [ @publisher= ] 'publisher'
    指定一个非 SQL Server 发布服务器。publisher 的数据类型为 sysname,默认值为 NULL。

    ms174958.note(zh-cn,SQL.90).gif注意:
    在 SQL Server 发布服务器中创建快照代理时,不应使用 publisher

返回代码值

0(成功)或 1(失败)

备注

sp_addpublication_snapshot 用于快照复制、事务复制和合并复制。

权限

只有 sysadmin 固定服务器角色成员或 db_owner 固定数据库角色成员才能执行 sp_addpublication_snapshot

示例

-- To avoid storing the login and password in the script file, the values 
-- are passed into SQLCMD as scripting variables. 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".

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publicationDB = N'AdventureWorks'; 
SET @publication = N'AdvWorksProductTran'; 
-- Windows account used to run the Log Reader and Snapshot Agents.
SET @login = $(Login); 
-- This should be passed at runtime.
SET @password = $(Password); 

-- Enable transactional or snapshot replication on the publication database.
EXEC sp_replicationdboption 
    @dbname=@publicationDB, 
    @optname=N'publish',
    @value = N'true';

-- Execute sp_addlogreader_agent to create the agent job. 
EXEC sp_addlogreader_agent 
    @job_login = @login, 
    @job_password = @password,
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;

-- Create a new transactional publication with the required properties. 
EXEC sp_addpublication 
    @publication = @publication, 
    @status = N'active',
    @allow_push = N'true',
    @allow_pull = N'true',
    @independent_agent = N'true';

-- Create a new snapshot job for the publication, using a default schedule.
EXEC sp_addpublication_snapshot 
    @publication = @publication, 
    @job_login = @login, 
    @job_password = @password,
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;
GO

请参阅

参考

sp_addpublication (Transact-SQL)
sp_changepublication_snapshot (Transact-SQL)
sp_startpublication_snapshot (Transact-SQL)
复制存储过程 (Transact-SQL)

其他资源

How to: Create a Publication (Replication Transact-SQL Programming)
创建并应用快照

帮助和信息

获取 SQL Server 2005 帮助

更改历史记录

发布日期 历史记录

2006 年 12 月 12 日

更新的内容:
  • 更新了关于 @frequency_type@frequency_interval 参数的信息。