방법: 정적 행 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)

테이블 아티클을 만들 때 WHERE 절을 정의하여 아티클에서 행을 필터링할 수 있습니다. 정의한 행 필터를 변경할 수도 있습니다. 복제 저장 프로시저를 사용하면 정적 행 필터를 프로그래밍 방식으로 만들거나 수정할 수 있습니다. 이러한 필터는 정적이므로 모든 구독자가 데이터의 동일한 하위 집합을 받습니다. 병합 게시에 속한 테이블 아티클에서 동적으로 행을 필터링하여 각 구독자가 서로 다른 데이터 파티션을 받게 하려면 방법: 병합 아티클에 대해 매개 변수가 있는 행 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오. 병합 게시에서도 기존 행 필터에 따라 관련 행을 필터링할 수 있습니다. 자세한 내용은 방법: 병합 아티클 간의 조인 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

스냅숏 또는 트랜잭션 게시에 대한 정적 행 필터를 정의하려면

  1. 필터링할 아티클을 정의합니다. 자세한 내용은 방법: 아티클 정의(복제 Transact-SQL 프로그래밍)를 참조하십시오.

  2. 게시 데이터베이스의 게시자에서 sp_articlefilter(Transact-SQL)를 실행합니다. 이때 @article에 아티클 이름, @publication에 게시 이름, @filter_name에 필터 이름, @filter_clause에 필터링 절(WHERE 포함하지 않음)을 지정합니다.

  3. 계속 열 필터를 정의하려면 방법: 열 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오. 그렇지 않으면 sp_articleview(Transact-SQL)를 실행합니다. 이때 @publication에 게시 이름, @article에 필터링된 아티클 이름, @filter_clause에 2단계에서 지정한 필터 절을 지정합니다. 이렇게 하면 필터링된 아티클에 대한 동기화 개체가 만들어집니다.

스냅숏 또는 트랜잭션 게시에 대한 정적 행 필터를 수정하려면

  1. 게시 데이터베이스의 게시자에서 sp_articlefilter(Transact-SQL)를 실행합니다. 이때 @article에 아티클 이름, @publication에 게시 이름, @filter_name에 새 필터 이름, @filter_clause에 새 필터링 절(WHERE 포함하지 않음)을 지정합니다. 이와 같이 변경하면 기존 구독의 데이터가 무효화되므로 @force_reinit_subscription1 값을 지정합니다.

  2. 게시 데이터베이스의 게시자에서 sp_articleview(Transact-SQL)를 실행합니다. 이때 @publication에 게시 이름, @article에 필터링된 아티클 이름, @filter_clause에 1단계에서 지정한 필터 절을 지정합니다. 이렇게 하면 필터링된 아티클을 정의하는 뷰가 다시 만들어집니다.

  3. 게시에 대해 스냅숏 에이전트 작업을 다시 실행하여 업데이트된 스냅숏을 생성합니다. 자세한 내용은 방법: 초기 스냅숏 만들기(복제 Transact-SQL 프로그래밍)를 참조하십시오.

  4. 구독을 다시 초기화합니다. 자세한 내용은 방법: 구독 다시 초기화(복제 Transact-SQL 프로그래밍)를 참조하십시오.

스냅숏 또는 트랜잭션 게시에 대한 정적 행 필터를 삭제하려면

  1. 게시 데이터베이스의 게시자에서 sp_articlefilter(Transact-SQL)를 실행합니다. 이때 @article에 아티클 이름, @publication에 게시 이름, @filter_name에 NULL 값, @filter_clause에 NULL 값을 지정합니다. 이와 같이 변경하면 기존 구독의 데이터가 무효화되므로 @force_reinit_subscription1 값을 지정합니다.

  2. 게시에 대해 스냅숏 에이전트 작업을 다시 실행하여 업데이트된 스냅숏을 생성합니다. 자세한 내용은 방법: 초기 스냅숏 만들기(복제 Transact-SQL 프로그래밍)를 참조하십시오.

  3. 구독을 다시 초기화합니다. 자세한 내용은 방법: 구독 다시 초기화(복제 Transact-SQL 프로그래밍)를 참조하십시오.

병합 게시에 대한 정적 행 필터를 정의하려면

  1. 게시 데이터베이스의 게시자에서 sp_addmergearticle (Transact-SQL)을 실행합니다. 이때 @subset_filterclause에 필터링 절(WHERE 포함하지 않음)을 지정합니다. 자세한 내용은 방법: 아티클 정의(복제 Transact-SQL 프로그래밍)를 참조하십시오.

  2. 계속 열 필터를 정의하려면 방법: 열 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

병합 게시에 대한 정적 행 필터를 수정하려면

  1. 게시 데이터베이스의 게시자에서 sp_changemergearticle(Transact-SQL)을 실행합니다. 이때 @publication에 게시 이름, @article에 필터링된 아티클 이름, @propertysubset_filterclause 값, @value에 새 필터링 절(WHERE 포함하지 않음)을 지정합니다. 이와 같이 변경하면 기존 구독의 데이터가 무효화되므로 @force_reinit_subscription1 값을 지정합니다.

  2. 게시에 대해 스냅숏 에이전트 작업을 다시 실행하여 업데이트된 스냅숏을 생성합니다. 자세한 내용은 방법: 초기 스냅숏 만들기(복제 Transact-SQL 프로그래밍)를 참조하십시오.

  3. 구독을 다시 초기화합니다. 자세한 내용은 방법: 구독 다시 초기화(복제 Transact-SQL 프로그래밍)를 참조하십시오.

다음 트랜잭션 복제 예에서는 지원되지 않는 모든 제품을 제거하도록 아티클을 행 필터링합니다.

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

다음 병합 복제 예에서는 지정된 영업 사원에 속한 행만 반환하도록 아티클을 행 필터링하고 조인 필터도 사용합니다. 자세한 내용은 방법: 병합 아티클 간의 조인 필터 정의 및 수정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

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