방법: 아티클 정의(복제 Transact-SQL 프로그래밍)

게시를 만든 후에 복제 저장 프로시저를 사용하여 아티클을 프로그래밍 방식으로 만들 수 있습니다. 아티클을 만드는 데 사용되는 저장 프로시저는 정의하려는 아티클의 게시 유형에 따라 달라집니다. 자세한 내용은 방법: 게시 만들기(복제 Transact-SQL 프로그래밍)를 참조하십시오.

[!참고]

아티클 이름에는 다음 문자를 사용할 수 없습니다. % , * , [ , ] , | , : , " , ? , ' , \ , / , < , >. 이러한 문자를 포함하는 데이터베이스 개체를 복제하려면 개체 이름과 다른 아티클 이름을 지정해야 합니다.

스냅숏 또는 트랜잭션 게시에 대한 아티클을 정의하려면

  1. 게시 데이터베이스의 게시자에서 sp_addarticle을 실행합니다. @publication에 아티클이 속한 게시의 이름을, @article에 아티클 이름을, @source_object에 게시할 데이터베이스 개체를 지정하고, 그 밖의 선택적 매개 변수를 지정합니다. dbo가 아닌 경우 @source_owner를 사용하여 개체의 스키마 소유권을 지정합니다. 로그 기반 테이블 아티클이 아니라면 @type에 아티클 유형을 지정합니다. 자세한 내용은 방법: 아티클 유형 정의(복제 Transact-SQL 프로그래밍)를 참조하십시오.

  2. 테이블의 행을 행 필터링하거나 아티클을 보려면 sp_articlefilter를 사용하여 필터 절을 정의합니다. 자세한 내용은 방법: 정적 행 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

  3. 테이블의 열을 열 필터링하거나 아티클을 보려면 sp_articlecolumn을 사용합니다. 자세한 내용은 방법: 열 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

  4. 아티클이 필터링되었으면 sp_articleview를 실행합니다.

  5. 게시에 기존 구독이 있고 sp_helppublicationimmediate_sync 열에 값 0을 반환하면 sp_addsubscription을 호출하여 각각의 기존 구독에 아티클을 추가해야 합니다.

  6. 게시에 기존 끌어오기 구독이 있으면 게시자에서 sp_refreshsubscriptions를 실행하여 새 아티클을 포함하는, 기존 끌어오기 구독에 대한 새 스냅숏을 만듭니다.

    [!참고]

    스냅숏을 사용하여 초기화되지 않은 구독에 대해서는 sp_refreshsubscriptions를 실행하지 않아도 됩니다. 이 절차는 sp_addarticle에 의해 실행됩니다.

병합 게시에 대한 아티클을 정의하려면

  1. 게시 데이터베이스의 게시자에서 sp_addmergearticle을 실행합니다. @publication에 게시의 이름을, @article에 아티클 이름을, @source_object에 게시할 개체를 지정합니다. 테이블 행을 행 필터링하려면 @subset_filterclause에 값을 지정합니다. 자세한 내용은 방법: 병합 아티클에 대해 매개 변수가 있는 행 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)방법: 정적 행 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오. 테이블 아티클이 아니라면 @type에 아티클 유형을 지정합니다. 자세한 내용은 방법: 아티클 유형 정의(복제 Transact-SQL 프로그래밍)를 참조하십시오.

  2. 필요에 따라 게시 데이터베이스의 게시자에서 sp_addmergefilter를 실행하여 두 아티클 간의 조인 필터를 정의합니다. 자세한 내용은 방법: 병합 아티클 간의 조인 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

  3. 필요에 따라 게시 데이터베이스의 게시자에서 sp_mergearticlecolumn을 실행하여 테이블 열을 필터링합니다. 자세한 내용은 방법: 열 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

이 예에서는 Product 테이블을 기반으로 트랜잭션 게시에 대한 아티클을 정의합니다. 여기에서 아티클은 행 및 열 방향으로 필터링됩니다.

DECLARE @publication    AS sysname;
DECLARE @table AS sysname;
DECLARE @filterclause AS nvarchar(500);
DECLARE @filtername AS nvarchar(386);
DECLARE @schemaowner AS sysname;
SET @publication = N'AdvWorksProductTran'; 
SET @table = N'Product';
SET @filterclause = N'[DiscontinuedDate] IS NULL'; 
SET @filtername = N'filter_out_discontinued';
SET @schemaowner = N'Production';

-- Add a horizontally and vertically filtered article for the Product table.
-- Manually set @schema_option to ensure that the Production schema 
-- is generated at the Subscriber (0x8000000).
EXEC sp_addarticle 
    @publication = @publication, 
    @article = @table, 
    @source_object = @table,
    @source_owner = @schemaowner, 
    @schema_option = 0x80030F3,
    @vertical_partition = N'true', 
    @type = N'logbased',
    @filter_clause = @filterclause;

-- (Optional) Manually call the stored procedure to create the 
-- horizontal filtering stored procedure. Since the type is 
-- 'logbased', this stored procedures is executed automatically.
EXEC sp_articlefilter 
    @publication = @publication, 
    @article = @table, 
    @filter_clause = @filterclause, 
    @filter_name = @filtername;

-- Add all columns to the article.
EXEC sp_articlecolumn 
    @publication = @publication, 
    @article = @table;

-- Remove the DaysToManufacture column from the article
EXEC sp_articlecolumn 
    @publication = @publication, 
    @article = @table, 
    @column = N'DaysToManufacture', 
    @operation = N'drop';

-- (Optional) Manually call the stored procedure to create the 
-- vertical filtering view. Since the type is 'logbased', 
-- this stored procedures is executed automatically.
EXEC sp_articleview 
    @publication = @publication, 
    @article = @table,
    @filter_clause = @filterclause;
GO

이 예에서는 병합 게시에 대한 아티클을 정의합니다. 여기에서 SalesOrderHeader 아티클은 SalesPersonID에 따라 정적으로 필터링되고 SalesOrderDetail 아티클은 SalesOrderHeader에 따라 조인 필터링됩니다.

DECLARE @publication AS sysname;
DECLARE @table1 AS sysname;
DECLARE @table2 AS sysname;
DECLARE @table3 AS sysname;
DECLARE @salesschema AS sysname;
DECLARE @hrschema AS sysname;
DECLARE @filterclause AS nvarchar(1000);
SET @publication = N'AdvWorksSalesOrdersMerge'; 
SET @table1 = N'Employee'; 
SET @table2 = N'SalesOrderHeader'; 
SET @table3 = N'SalesOrderDetail'; 
SET @salesschema = N'Sales';
SET @hrschema = N'HumanResources';
SET @filterclause = N'Employee.LoginID = HOST_NAME()';

-- Add a filtered article for the Employee table.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table1, 
  @source_object = @table1, 
  @type = N'table', 
  @source_owner = @hrschema,
  @schema_option = 0x0004CF1,
  @description = N'article for the Employee table',
  @subset_filterclause = @filterclause;

-- Add an article for the SalesOrderHeader table that is filtered
-- based on Employee and horizontally filtered.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table2, 
  @source_object = @table2, 
  @type = N'table', 
  @source_owner = @salesschema, 
  @vertical_partition = N'true',
  @schema_option = 0x0034EF1,
  @description = N'article for the SalesOrderDetail table';

-- Add an article for the SalesOrderDetail table that is filtered
-- based on SaledOrderHeader.
EXEC sp_addmergearticle 
  @publication = @publication, 
  @article = @table3, 
  @source_object = @table3, 
  @source_owner = @salesschema,
  @description = 'article for the SalesOrderHeader table', 
  @identityrangemanagementoption = N'auto', 
  @pub_identity_range = 100000, 
  @identity_range = 100, 
  @threshold = 80,
  @schema_option = 0x0004EF1;

-- Add all columns to the SalesOrderHeader article.
EXEC sp_mergearticlecolumn 
  @publication = @publication, 
  @article = @table2, 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Remove the credit card Approval Code column.
EXEC sp_mergearticlecolumn 
  @publication = @publication, 
  @article = @table2, 
  @column = N'CreditCardApprovalCode', 
  @operation = N'drop', 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Add a merge join filter between Employee and SalesOrderHeader.
EXEC sp_addmergefilter 
  @publication = @publication, 
  @article = @table2, 
  @filtername = N'SalesOrderHeader_Employee', 
  @join_articlename = @table1, 
  @join_filterclause = N'Employee.EmployeeID = SalesOrderHeader.SalesPersonID', 
  @join_unique_key = 1, 
  @filter_type = 1, 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;

-- Add a merge join filter between SalesOrderHeader and SalesOrderDetail.
EXEC sp_addmergefilter 
  @publication = @publication, 
  @article = @table3, 
  @filtername = N'SalesOrderDetail_SalesOrderHeader', 
  @join_articlename = @table2, 
  @join_filterclause = N'SalesOrderHeader.SalesOrderID = SalesOrderDetail.SalesOrderID', 
  @join_unique_key = 1, 
  @filter_type = 1, 
  @force_invalidate_snapshot = 1, 
  @force_reinit_subscription = 1;
GO