sp_addpublication_snapshot(Transact-SQL)

지정된 게시에 대해 스냅숏 에이전트를 만듭니다. 이 저장 프로시저는 게시 데이터베이스의 게시자에서 실행됩니다.

보안 정보보안 정보

게시자를 원격 배포자로 구성할 경우 job_login 및 job_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

    매월(frequency_interval에 따라 달라짐)

    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은 다음 중 하나 이상을 조합하여 사용할 수 있습니다. 조합 시 | (비트 OR) 논리 연산자를 사용합니다.

    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이며 기본값은 9999년 12월 31일을 의미하는 9991231입니다.

  • [ @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이며 기본값은 24시간 시계를 기준으로 하여 11:59:59 P.M.을 의미하는 235959입니다.

  • [ @snapshot_job_name = ] 'snapshot_agent_name'
    기존 작업을 사용 중일 때 기존 스냅숏 에이전트 작업의 이름입니다. snapshot_agent_name은 nvarchar(100)이며 기본값은 NULL입니다. 이 매개 변수는 내부용이고 새 게시를 만들 때 지정되지 않아야 합니다. snapshot_agent_name을 지정하는 경우에는 job_login 및 job_password가 NULL이어야 합니다.

  • [ @publisher_security_mode= ] publisher_security_mode
    게시자에 연결할 때 에이전트가 사용하는 보안 모드입니다. publisher_security_mode는 smallint이며 기본값은 1입니다. 0은 SQL Server 인증을 지정하고 1은 Windows 인증을 지정합니다. SQL Server 이외 게시자에 대해서는 값 0을 지정해야 합니다. 가능하면 Windows 인증을 사용하십시오.

  • [ @publisher_login= ] 'publisher_login'
    게시자에 연결할 때 사용되는 로그인입니다. publisher_login은 sysname이며 기본값은 NULL입니다. publisher_security_mode가 0인 경우 publisher_login을 지정해야 합니다. publisher_login이 NULL이고 publisher_security_mode가 1이면 게시자에 연결할 때 job_login에 지정된 Windows 계정이 사용됩니다.

  • [ @publisher_password= ] 'publisher_password'
    게시자에 연결할 때 사용되는 암호입니다. publisher_password는 sysname이며 기본값은 NULL입니다.

    보안 정보보안 정보

    스크립트 파일에 인증 정보를 저장하지 않도록 합니다. 보안 향상을 위해 런타임에 로그인 이름과 암호를 제공하는 것이 좋습니다.

  • [ @job_login= ] 'job_login'
    에이전트가 실행되는 Windows 계정의 로그인입니다. job_login은 nvarchar(257)이며 기본값은 NULL입니다. 이 Windows 계정은 에이전트가 배포자에 연결할 때 항상 사용됩니다. 새 스냅숏 에이전트 작업을 만들 때는 이 매개 변수를 제공해야 합니다.

    [!참고]

    Microsoft SQL Server 이외 게시자의 경우 sp_adddistpublisher(Transact-SQL)에 지정된 동일한 로그인이어야 합니다.

  • [ @job_password= ] 'job_password'
    에이전트를 실행하는 Windows 계정의 암호입니다. job_password는 sysname이며 기본값은 없습니다. 새 스냅숏 에이전트 작업을 만들 때는 이 매개 변수를 제공해야 합니다.

    보안 정보보안 정보

    스크립트 파일에 인증 정보를 저장하지 않도록 합니다. 보안 향상을 위해 런타임에 로그인 이름과 암호를 제공하는 것이 좋습니다.

  • [ @publisher = ] 'publisher'
    SQL Server 이외 게시자를 지정합니다. publisher는 sysname이며 기본값은 NULL입니다.

    [!참고]

    SQL Server 게시자에서 스냅숏 에이전트를 생성할 때는 publisher를 사용하면 안 됩니다.

반환 코드 값

0(성공) 또는 1(실패)

주의

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

사용 권한

sysadmin 고정 서버 역할의 멤버 또는 db_owner 고정 데이터베이스 역할의 멤버만이 sp_addpublication_snapshot을 실행할 수 있습니다.