sp_adddynamicsnapshot_job(Transact-SQL)

매개 변수가 있는 행 필터로 게시에 대한 필터링된 데이터 스냅숏을 생성하는 에이전트 작업을 만듭니다. 이 저장 프로시저는 게시 데이터베이스의 게시자에서 실행됩니다. 관리자가 이 저장 프로시저를 사용하여 구독자에 대한 필터링된 데이터 스냅숏 작업을 수동으로 만들 수 있습니다.

[!참고]

필터링된 데이터 스냅숏 작업을 만들려면 게시에 대한 표준 스냅숏 작업이 있어야 합니다.

자세한 내용은 매개 변수가 있는 필터를 사용하는 병합 게시의 스냅숏을 참조하십시오.

항목 링크 아이콘Transact-SQL 구문 표기 규칙

구문

sp_adddynamicsnapshot_job [ @publication = ] 'publication' 
    [ , [ @suser_sname = ] 'suser_sname' ] 
    [ , [ @host_name = ] 'host_name' ] 
    [ , [ @dynamic_snapshot_jobname = ] 'dynamic_snapshot_jobname' OUTPUT ] 
    [ , [ @dynamic_snapshot_jobid = ] 'dynamic_snapshot_jobid' OUTPUT ] 
    [ , [ @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 ]

인수

  • [ @publication=] 'publication'
    필터링된 데이터 스냅숏 작업이 추가될 게시의 이름입니다. publicationsysname이며 기본값은 없습니다.

  • [ @suser_sname= ] 'suser_sname'
    구독에 대한 필터링된 데이터 스냅숏을 만들 때 사용되는 값으로, 구독자의 SUSER_SNAME 함수 값으로 필터링됩니다. suser_snamesysname이며 기본값은 없습니다. 이 함수를 사용하여 게시를 동적으로 필터링하지 않은 경우 suser_sname은 NULL이어야 합니다.

  • [ @host_name= ] 'host_name'
    구독에 대한 필터링된 데이터 스냅숏을 만들 때 사용되는 값으로, 구독자의 HOST_NAME 함수 값으로 필터링됩니다. host_namesysname이며 기본값은 없습니다. 게시를 동적으로 필러팅하는 데 이 함수를 사용하지 않는 경우 host_name은 NULL이어야 합니다.

  • [ @dynamic_snapshot_jobname= ] 'dynamic_snapshot_jobname'
    만들어진 필터링된 데이터 스냅숏 작업의 이름입니다. dynamic_snapshot_jobname은 기본값이 NULL인 sysname이며 선택적인 OUTPUT 매개 변수입니다. dynamic_snapshot_jobname을 지정한 경우 이 이름은 배포자에서 고유한 작업으로 확인되어야 합니다. 지정하지 않은 경우 작업 이름이 자동으로 생성되고 결과 집합에 반환됩니다. 생성되는 이름은 다음과 같습니다.

    'dyn_' + <name of the standard snapshot job> + <GUID>
    

    [!참고]

    동적 스냅숏 작업 이름을 생성할 때 표준 스냅숏 작업 이름을 잘라낼 수 있습니다.

  • [ @dynamic_snapshot_jobid= ] 'dynamic_snapshot_jobid'
    만들어진 필터링된 데이터 스냅숏의 식별자입니다. dynamic_snapshot_jobid는 기본값이 NULL인 uniqueidentifier이며 선택적인 OUTPUT 매개 변수입니다.

  • [ @frequency_type=] frequency_type
    필터링된 데이터 스냅숏 작업을 예약하는 빈도입니다. frequency_typeint이며 다음 값 중 하나일 수 있습니다.

    설명

    1

    한 번

    2

    요청 시

    4(기본값)

    매일

    8

    매주

    16

    매월

    32

    매월 상대적

    64

    자동 시작

    128

    되풀이

  • [ @frequency_interval = ] frequency_interval
    필터링된 데이터 스냅숏 작업을 실행할 기간(일)입니다. frequency_interval은 기본값이 1인 int이며 frequency_type 값에 따라 달라집니다.

    frequency_type

    frequency_interval에 미치는 영향

    1

    frequency_interval은 사용되지 않습니다.

    4(기본값)

    frequency_interval일마다(기본값 매일)

    8

    frequency_interval은 다음 중 하나 이상을 조합하여 사용할 수 있습니다. 조합 시 |(비트 OR)(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
    frequency_subday_interval의 단위를 지정합니다. frequency_subdayint이며 다음 값 중 하나일 수 있습니다.

    설명

    1

    한 번

    2

    4(기본값)

    8

  • [ @frequency_subday_interval=] frequency_subday_interval
    각 작업 실행 사이의 frequency_subday 기간(일)입니다. frequency_subday_intervalint이며 기본값은 5입니다.

  • [ @frequency_relative_interval=] frequency_relative_interval
    각 월에 필터링된 데이터 스냅숏 작업이 발생하는 빈도입니다. 이 매개 변수는 frequency_type32(매월 상대적)로 설정된 경우 사용됩니다. frequency_relative_intervalint이며 다음 값 중 하나일 수 있습니다.

    설명

    1(기본값)

    첫째

    2

    둘째

    4

    셋째

    8

    넷째

    16

    마지막

  • [ @frequency_recurrence_factor=] frequency_recurrence_factor
    frequency_type에 사용되는 되풀이 비율입니다. frequency_recurrence_factorint이며 기본값은 0입니다.

  • [ @active_start_date=] active_start_date
    필터링된 데이터 스냅숏 작업이 처음으로 실행되도록 예약된 날짜이며 YYYYMMDD 형식으로 표시됩니다. active_start_dateint이며 기본값은 NULL입니다.

  • [ @active_end_date=] active_end_date
    필터링된 데이터 스냅숏 작업이 마지막으로 실행되도록 예약된 날짜이며 YYYYMMDD 형식으로 표시됩니다. active_end_dateint이며 기본값은 NULL입니다.

  • [ @active_start_time_of_day=] active_start_time_of_day
    하루 중에서 필터링된 데이터 스냅숏 작업이 처음으로 실행되도록 예약된 시간이며 HHMMSS 형식으로 표시됩니다. active_start_time_of_dayint이며 기본값은 NULL입니다.

  • [ @active_end_time_of_day=] active_end_time_of_day
    하루 중에서 필터링된 데이터 스냅숏 작업이 중단되도록 예약된 시간이며 HHMMSS 형식으로 표시됩니다. active_end_time_of_dayint이며 기본값은 NULL입니다.

결과 집합

열 이름

데이터 형식

설명

id

int

MSdynamicsnapshotjobs 시스템 테이블에서 필터링된 데이터 스냅숏 작업을 식별합니다.

dynamic_snapshot_jobname

sysname

필터링된 데이터 스냅숏 작업의 이름입니다.

dynamic_snapshot_jobid

uniqueidentifier

배포자에서 Microsoft SQL Server 에이전트 작업을 고유하게 식별합니다.

반환 코드 값

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

주의

sp_adddynamicsnapshot_job은 매개 변수가 있는 필터를 사용하는 게시의 병합 복제에 사용됩니다.

-- To avoid storing the login and 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".

--Add a new merge publication.
DECLARE @publicationdb AS sysname;
DECLARE @publication AS sysname;
DECLARE @table1 AS sysname;
DECLARE @table2 AS sysname;
DECLARE @filter AS sysname;
DECLARE @schema_hr AS sysname;
DECLARE @schema_sales AS sysname;

SET @publicationdb = N'AdventureWorks2008R2';
SET @publication = N'AdvWorksSalesPersonMerge';
SET @table1 = N'Employee';
SET @table2 = N'SalesPerson';
SET @filter = N'SalesPerson_Employee';
SET @schema_hr = N'HumanResources';
SET @schema_sales = N'Sales';

USE [AdventureWorks2008R2];

-- Enable AdventureWorks2008R2 for merge replication.
EXEC sp_replicationdboption
  @dbname = @publicationdb,
  @optname = N'merge publish',
  @value = N'true';  

-- Create new merge publication.  
EXEC sp_addmergepublication 
  @publication = @publication, 
  @description = N'Merge publication of AdventureWorks2008R2.', 
  @allow_subscriber_initiated_snapshot = N'false';

-- Create a new snapshot job for the publication, using the 
-- default schedule. Pass credentials at runtime using 
-- sqlcmd scripting variables.
EXEC sp_addpublication_snapshot 
  @publication = @publication, 
  @job_login = $(Login), 
  @job_password = $(password);

-- Add an article for the Employee table, 
-- which is horizontally partitioned using 
-- a parameterized row filter.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table1, 
  @source_owner = @schema_hr, 
  @source_object = @table1, 
  @type = N'table', 
  @description = 'contains employee information', 
  @subset_filterclause = N'[LoginID] = HOST_NAME()';

-- Add an article for the SalesPerson table, 
-- which is partitioned based on a join filter.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table2, 
  @source_owner = @schema_sales, 
  @source_object = @table2, 
  @type = N'table', 
  @description = 'contains customer information';

-- Add a join filter between the two articles.
EXEC sp_addmergefilter 
  @publication = @publication, 
  @article = @table1, 
  @filtername = @filter, 
  @join_articlename = @table2, 
  @join_filterclause = N'[Employee].[BusinessEntityID] = [SalesPerson].[SalesPersonID]', 
  @join_unique_key = 1, 
  @filter_type = 1;
GO

-- Start the snapshot agent job.
DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesPersonMerge';

EXEC sp_startpublication_snapshot 
  @publication = @publication;
GO

PRINT '*** Waiting for the initial snapshot.';
GO

-- Create a temporary table to store the filtered data snapshot 
-- job information.
CREATE TABLE #temp (id int,
    job_name sysname,
    job_id uniqueidentifier,
    dynamic_filter_login sysname NULL,
    dynamic_filter_hostname sysname NULL,
    dynamic_snapshot_location nvarchar(255),
    frequency_type int, 
    frequency_interval int, 
    frequency_subday_type int,
    frequency_subday_interval int, 
    frequency_relative_interval int, 
    frequency_recurrence_factor int, 
    active_start_date int, 
    active_end_date int, 
    active_start_time int, 
    active_end_time int
)

-- Create each snapshot for a partition 
-- The initial snapshot must already be generated.
DECLARE @publication AS sysname;
DECLARE @jobname AS sysname
DECLARE @hostname AS sysname
SET @publication = N'AdvWorksSalesPersonMerge';
SET @hostname = N'adventure-works\Fernando';

WHILE NOT EXISTS(SELECT * FROM sysmergepublications 
    WHERE [name] = @publication 
    AND snapshot_ready = 1)
BEGIN
    WAITFOR DELAY '00:00:05'
END

-- Create a data partition by overriding HOST_NAME().
EXEC sp_addmergepartition 
  @publication = @publication,
  @host_name = @hostname;

-- Create the filtered data snapshot job, and use the returned 
-- information to start the job.
EXEC sp_adddynamicsnapshot_job 
  @publication = @publication,
  @host_name = @hostname;

INSERT INTO #temp (id, job_name, job_id, dynamic_filter_login,
    dynamic_filter_hostname, dynamic_snapshot_location,
    frequency_type, frequency_interval, frequency_subday_type,
    frequency_subday_interval, frequency_relative_interval, 
    frequency_recurrence_factor, active_start_date, active_end_date, 
    active_start_time,active_end_time)
EXEC sp_helpdynamicsnapshot_job;

SELECT @jobname = (SELECT DISTINCT job_name FROM #temp WHERE dynamic_filter_hostname = @hostname);

EXEC msdb..sp_start_job @job_name = @jobname;
DROP TABLE #temp;
GO

사용 권한

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