아티클 정의Define an Article

이 항목에서는 SQL Server 2017SQL Server 2017 , SQL Server Management StudioSQL Server Management Studio또는 RMO(복제 관리 개체)를 사용하여 Transact-SQLTransact-SQL에서 아티클을 정의하는 방법에 대해 설명합니다.This topic describes how to define an article in SQL Server 2017SQL Server 2017 by using SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or Replication Management Objects (RMO).

항목 내용In This Topic

시작하기 전 주의 사항 Before You Begin

제한 사항 Limitations and Restrictions

  • 아티클 이름에는 %, *, [,], |, :, ", ? 등의 문자를 포함할 수 없습니다.Article names cannot include any of the following characters: % , * , [ , ] , | , : , " , ? , ' , \ , / , < , >., ' , \ , / , < , >. 이러한 문자를 포함하는 데이터베이스 개체를 복제하려면 개체 이름과 다른 아티클 이름을 지정해야 합니다.If objects in the database include any of these characters and you want to replicate them, you must specify an article name that is different from the object name.

보안 Security

가능한 경우 런타임 시 사용자에게 보안 자격 증명을 입력하라는 메시지가 표시됩니다.When possible, prompt users to enter security credentials at runtime. 자격 증명을 저장해야 하는 경우 Windows .NET Framework에서 제공하는 암호화 서비스 MicrosoftMicrosoft 를 사용합니다.If you must store credentials, use the cryptographic services provided by the MicrosoftMicrosoft Windows .NET Framework.

SQL Server Management Studio 사용 Using SQL Server Management Studio

새 게시 마법사를 사용하여 게시를 만들고 아티클을 정의할 수 있습니다.Create publications and define articles with the New Publication Wizard. 게시를 만든 후 게시 속성 - <게시> 대화 상자에서 게시 속성을 보고 수정합니다.After a publication is created, view and modify publication properties in the Publication Properties - <Publication> dialog box. Oracle 데이터베이스에서 게시를 만드는 방법에 대한 자세한 내용은 Oracle 데이터베이스에서 게시 만들기를 참조하세요.For information about creating a publication from an Oracle database, see Create a Publication from an Oracle Database.

게시를 만들고 아티클을 정의하려면To create a publication and define articles

  1. MicrosoftMicrosoft SQL Server Management StudioSQL Server Management Studio에서 게시자에 연결한 다음 해당 서버 노드를 확장합니다.Connect to the Publisher in MicrosoftMicrosoft SQL Server Management StudioSQL Server Management Studio, and then expand the server node.

  2. 복제 폴더를 확장한 다음 로컬 게시 폴더를 마우스 오른쪽 단추로 클릭합니다.Expand the Replication folder, and then right-click the Local Publications folder.

  3. 새 게시를 클릭합니다.Click New Publication.

  4. 새 게시 마법사의 페이지에 따라 다음을 수행하세요.Follow the pages in the New Publication Wizard to:

    • 서버에 배포가 구성되어 있지 않은 경우 배포자를 지정합니다.Specify a Distributor if distribution has not been configured on the server. 배포 구성에 대한 자세한 내용은 게시 및 배포 구성을 참조하세요.For more information about configuring distribution, see Configure Publishing and Distribution.

      배포자 페이지에서 게시자 서버가 자신의 고유 배포자(로컬 배포자) 역할을 하는 것으로 지정했지만 서버가 배포자로 구성되어 있지 않은 경우 새 게시 마법사가 서버를 구성합니다.If you specify on the Distributor page that the Publisher server will act as its own Distributor (a local Distributor), and the server is not configured as a Distributor, the New Publication Wizard will configure the server. 스냅숏 폴더 페이지에서 배포자에 대해 기본 스냅숏 폴더를 지정하게 됩니다.You will specify a default snapshot folder for the Distributor on the Snapshot Folder page. 스냅숏 폴더는 공유하도록 지정된 디렉터리일 뿐이며 이 폴더에 읽기/쓰기 작업을 수행하려면 에이전트에게 충분한 액세스 권한이 있어야 합니다.The snapshot folder is simply a directory that you have designated as a share; agents that read from and write to this folder must have sufficient permissions to access it. 폴더의 적절한 보안 유지 방법에 대한 자세한 내용은 스냅숏 폴더 보안 설정을 참조하세요.For more information about securing the folder appropriately, see Secure the Snapshot Folder.

      다른 서버가 배포자의 역할을 하도록 지정한 경우 게시자에서 배포자로 연결할 때 사용할 암호를 관리 암호 페이지에 입력해야 합니다.If you specify that another server should act as the Distributor, you must enter a password on the Administrative Password page for connections made from the Publisher to the Distributor. 이 암호는 원격 배포자에서 게시자를 설정할 때 지정한 암호와 일치해야 합니다.This password must match the password specified when the Publisher was enabled at the remote Distributor.

      자세한 내용은 배포 구성을 참조하세요.For more information, see Configure Distribution.

    • 게시 데이터베이스를 선택합니다.Choose a publication database.

    • 보고서 유형을 선택합니다.Select a publication type. 자세한 내용은 복제 유형을 참조하세요.For more information, see Types of Replication.

    • 게시할 데이터와 데이터베이스 개체를 지정합니다. 필요에 따라 테이블 아티클에서 열을 필터링하고 아티클 속성을 설정합니다.Specify data and database objects to publish; optionally filter columns from table articles, and set article properties.

    • 필요에 따라 테이블 아티클에서 행을 필터링합니다.Optionally filter rows from table articles. 자세한 내용은 게시된 데이터 필터링을 참조하세요.For more information, see Filter Published Data.

    • 스냅숏 에이전트 일정을 설정합니다.Set the Snapshot Agent schedule.

    • 다음 복제 에이전트를 실행 및 연결하는 자격 증명을 지정합니다.Specify the credentials under which the following replication agents run and make connections:

      모든 게시에 대한 - 스냅숏 에이전트- Snapshot Agent for all publications.

      모든 트랜잭션 게시에 대한 - 로그 판독기 에이전트- Log Reader Agent for all transactional publications.

      - 구독 업데이트를 허용하는 트랜잭션 게시에 대한 큐 판독기 에이전트- Queue Reader Agent for transactional publications that allow updating subscriptions.

      자세한 내용은 복제 에이전트 보안 모델복제 보안을 위한 최선의 구현 방법를 참조하세요.For more information, see Replication Agent Security Model and Replication Security Best Practices.

    • 필요에 따라 게시를 스크립팅합니다.Optionally script the publication. 자세한 내용은 스크립팅 복제을 참조하세요.For more information, see Scripting Replication.

    • 게시의 이름을 지정합니다.Specify a name for the publication.

Transact-SQL 사용 Using Transact-SQL

게시를 만든 후에 복제 저장 프로시저를 사용하여 아티클을 프로그래밍 방식으로 만들 수 있습니다.After a publication has been created, articles can be created programmatically using replication stored procedures. 아티클을 만드는 데 사용되는 저장 프로시저는 정의하려는 아티클의 게시 유형에 따라 달라집니다.The stored procedures used to create an article will depend on the type of publication for which the article is being defined. 자세한 내용은 게시 만들기를 참조하세요.For more information, see Create a Publication.

스냅숏 또는 트랜잭션 게시에 대한 아티클을 정의하려면To define an article for a Snapshot or Transactional Publication

  1. 게시 데이터베이스의 게시자에서 sp_addarticle을 실행합니다.At the Publisher on the publication database, execute sp_addarticle. @publication에 아티클이 속한 게시의 이름을, @article에 아티클 이름을, @source_object에 게시되는 데이터베이스 개체를 지정하고, 그 밖의 선택적 매개 변수를 지정합니다.Specify the name of the publication to which the article belongs for @publication, a name for the article for @article, the database object being published for @source_object, and any other optional parameters. dbo가 아닌 경우 @source_owner를 사용하여 개체의 스키마 소유권을 지정합니다.Use @source_owner to specify the schema ownership of the object, if not dbo. 로그 기반 테이블 아티클이 아닌 경우 @type에 아티클 유형을 지정합니다. 자세한 내용은 아티클 유형 지정(복제 Transact-SQL 프로그래밍)을 참조하세요.If the article is not a log-based table article, specify the article type for @type; for more information, see Specify Article Types (Replication Transact-SQL Programming).

  2. 테이블의 행을 행 필터링하거나 아티클을 보려면 sp_articlefilter 를 사용하여 필터 절을 정의합니다.To horizontally filter rows in a table or view an article, use sp_articlefilter to define the filter clause. 자세한 내용은 정적 행 필터 정의 및 수정을 참조하세요.For more information, see Define and Modify a Static Row Filter.

  3. 테이블의 열을 열 필터링하거나 아티클을 보려면 sp_articlecolumn을 사용합니다.To vertically filter columns in a table or view an article, use sp_articlecolumn. 자세한 내용은 열 필터 정의 및 수정을 참조하세요.For more information, see Define and Modify a Column Filter.

  4. 아티클이 필터링되었으면 sp_articleview 를 실행합니다.Execute sp_articleview if the article is filtered.

  5. 게시에 기존 구독이 있고 sp_helppublicationimmediate_sync 열에 값 0 을 반환하면 sp_addsubscription 을 호출하여 각각의 기존 구독에 아티클을 추가해야 합니다.If the publication has existing subscriptions and sp_helppublication returns a value of 0 in the immediate_sync column, you must call sp_addsubscription to add the article to each existing subscription.

  6. 게시에 기존 끌어오기 구독이 있으면 게시자에서 sp_refreshsubscriptions 를 실행하여 새 아티클을 포함하는, 기존 끌어오기 구독에 대한 새 스냅숏을 만듭니다.If the publication has existing pull subscriptions, execute sp_refreshsubscriptions at the Publisher to create a new snapshot for existing pull subscriptions that contains just the new article.

    참고

    스냅숏을 사용하여 초기화되지 않은 구독에 대해서는 sp_refreshsubscriptions 를 실행하지 않아도 됩니다. 이 절차는 sp_addarticle에 의해 실행됩니다.For subscriptions that are not initialized using a snapshot, you do not need to execute sp_refreshsubscriptions as this procedure is executed by sp_addarticle.

병합 게시에 대한 아티클을 정의하려면To define an article for a Merge Publication

  1. 게시 데이터베이스의 게시자에서 sp_addmergearticle을 실행합니다.At the Publisher on the publication database, execute sp_addmergearticle. @publication에 게시 이름을, @article에 아티클 이름을, @source_object에 게시되는 개체를 지정합니다.Specify the name of the publication for @publication, a name for the article name for @article, and the object being published for @source_object. 테이블 행을 행 필터링하려면 @subset_filterclause를 참조하세요.To horizontally filter table rows, specify a value for @subset_filterclause. 자세한 내용은 병합 아티클에 대한 매개 변수가 있는 행 필터 정의 및 수정정적 행 필터 정의 및 수정를 참조하세요.For more information, see Define and Modify a Parameterized Row Filter for a Merge Article and Define and Modify a Static Row Filter. 테이블 아티클이 아니라면 @type를 참조하세요.If the article is not a table article, specify the article type for @type. 자세한 내용은 아티클 유형 정의(복제 Transact-SQL 프로그래밍)를 참조하세요.For more information, see Specify Article Types (Replication Transact-SQL Programming).

  2. 필요에 따라 게시 데이터베이스의 게시자에서 sp_addmergefilter 를 실행하여 두 아티클 간의 조인 필터를 정의합니다.(Optional) At the Publisher on the publication database, execute sp_addmergefilter to define a join filter between two articles. 자세한 내용은 병합 아티클 사이에서 조인 필터 정의 및 수정을 참조하세요.For more information, see Define and Modify a Join Filter Between Merge Articles.

  3. 필요에 따라 게시 데이터베이스의 게시자에서 sp_mergearticlecolumn 을 실행하여 테이블 열을 필터링합니다.(Optional) At the Publisher on the publication database, execute sp_mergearticlecolumn to filter table columns. 자세한 내용은 열 필터 정의 및 수정을 참조하세요.For more information, see Define and Modify a Column Filter.

예(Transact-SQL) Examples (Transact-SQL)

이 예에서는 Product 테이블을 기반으로 트랜잭션 게시에 대한 아티클을 정의합니다. 여기에서 아티클은 행 및 열 방향으로 필터링됩니다.This example defines an article based on the Product table for a transactional publication, where the article is filtered both horizontally and vertically.

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에 따라 조인 필터링됩니다.This example defines articles for a merge publication, where the SalesOrderHeader article is statically filtered based on SalesPersonID, and the SalesOrderDetail article is join filtered based on 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.BusinessEntityID = 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

RMO(복제 관리 개체) 사용 Using Replication Management Objects (RMO)

RMO(복제 관리 개체)를 사용하여 프로그래밍 방식으로 아티클을 정의할 수 있습니다.You can define articles programmatically by using Replication Management Objects (RMO). 아티클을 정의하는 데 사용하는 RMO 클래스는 정의되는 아티클의 게시 유형에 따라 달라집니다.The RMO classes that you use to define an article depend on the type of publication for which the article is defined.

예(RMO) Examples (RMO)

다음 예에서는 행 및 열 필터가 포함된 아티클을 트랜잭션 게시에 추가합니다.The following example adds an article with row and column filters to a transactional publication.

// Define the Publisher, publication, and article names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
string articleName = "Product";
string schemaOwner = "Production";

TransArticle article;

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

// Create a filtered transactional articles in the following steps:
// 1) Create the  article with a horizontal filter clause.
// 2) Add columns to or remove columns from the article.
try
{
	// Connect to the Publisher.
	conn.Connect();

	// Define a horizontally filtered, log-based table article.
	article = new TransArticle();
	article.ConnectionContext = conn;
	article.Name = articleName;
	article.DatabaseName = publicationDbName;
	article.SourceObjectName = articleName;
	article.SourceObjectOwner = schemaOwner;
	article.PublicationName = publicationName;
	article.Type = ArticleOptions.LogBased;
	article.FilterClause = "DiscontinuedDate IS NULL";

	// Ensure that we create the schema owner at the Subscriber.
	article.SchemaOption |= CreationScriptOptions.Schema;

	if (!article.IsExistingObject)
	{
		// Create the article.
		article.Create();
	}
	else
	{
		throw new ApplicationException(String.Format(
			"The article {0} already exists in publication {1}.",
			articleName, publicationName));
	}

	// Create an array of column names to remove from the article.
	String[] columns = new String[1];
	columns[0] = "DaysToManufacture";

	// Remove the column from the article.
	article.RemoveReplicatedColumns(columns);
}
catch (Exception ex)
{
	// Implement appropriate error handling here.
	throw new ApplicationException("The article could not be created.", ex);
}
finally
{
	conn.Disconnect();
}
' Define the Publisher, publication, and article names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim articleName As String = "Product"
Dim schemaOwner As String = "Production"

Dim article As TransArticle

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

' Create a filtered transactional articles in the following steps:
' 1) Create the  article with a horizontal filter clause.
' 2) Add columns to or remove columns from the article.
Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Define a horizontally filtered, log-based table article.
    article = New TransArticle()
    article.ConnectionContext = conn
    article.Name = articleName
    article.DatabaseName = publicationDbName
    article.SourceObjectName = articleName
    article.SourceObjectOwner = schemaOwner
    article.PublicationName = publicationName
    article.Type = ArticleOptions.LogBased
    article.FilterClause = "DiscontinuedDate IS NULL"

    ' Ensure that we create the schema owner at the Subscriber.
    article.SchemaOption = article.SchemaOption Or _
    CreationScriptOptions.Schema

    If Not article.IsExistingObject Then
        ' Create the article.
        article.Create()
    Else
        Throw New ApplicationException(String.Format( _
         "The article {0} already exists in publication {1}.", _
         articleName, publicationName))
    End If

    ' Create an array of column names to remove from the article.
    Dim columns() As String = New String(0) {}
    columns(0) = "DaysToManufacture"

    ' Remove the column from the article.
    article.RemoveReplicatedColumns(columns)
Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The article could not be created.", ex)
Finally
    conn.Disconnect()
End Try

다음 예에서는 병합 게시에 세 개의 아티클을 추가합니다.The following example adds three articles to a merge publication. 이 아티클에는 열 필터가 포함되며, 두 개의 조인 필터를 사용하여 매개 변수가 있는 행 필터를 다른 아티클에 전파합니다.The articles have column filters, and two join filters are used to propagate a parameterized row filter to the other articles.

// Define the Publisher and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";

// Specify article names.
string articleName1 = "Employee";
string articleName2 = "SalesOrderHeader";
string articleName3 = "SalesOrderDetail";

// Specify join filter information.
string filterName12 = "SalesOrderHeader_Employee";
string filterClause12 = "Employee.EmployeeID = " +
	"SalesOrderHeader.SalesPersonID";
string filterName23 = "SalesOrderDetail_SalesOrderHeader";
string filterClause23 = "SalesOrderHeader.SalesOrderID = " +
	"SalesOrderDetail.SalesOrderID";

string salesSchema = "Sales";
string hrSchema = "HumanResources";

MergeArticle article1 = new MergeArticle();
MergeArticle article2 = new MergeArticle();
MergeArticle article3 = new MergeArticle();
MergeJoinFilter filter12 = new MergeJoinFilter();
MergeJoinFilter filter23 = new MergeJoinFilter();

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

// Create three merge articles that are horizontally partitioned
// using a parameterized row filter on Employee.EmployeeID, which is 
// extended to the two other articles using join filters. 
try
{
	// Connect to the Publisher.
	conn.Connect();

	// Create each article. 
	// For clarity, each article is defined separately. 
	// In practice, iterative structures and arrays should 
	// be used to efficiently create multiple articles.

	// Set the required properties for the Employee article.
	article1.ConnectionContext = conn;
	article1.Name = articleName1;
	article1.DatabaseName = publicationDbName;
	article1.SourceObjectName = articleName1;
	article1.SourceObjectOwner = hrSchema;
	article1.PublicationName = publicationName;
	article1.Type = ArticleOptions.TableBased;

	// Define the parameterized filter clause based on Hostname.
	article1.FilterClause = "Employee.LoginID = HOST_NAME()";

	// Set the required properties for the SalesOrderHeader article.
	article2.ConnectionContext = conn;
	article2.Name = articleName2;
	article2.DatabaseName = publicationDbName;
	article2.SourceObjectName = articleName2;
	article2.SourceObjectOwner = salesSchema;
	article2.PublicationName = publicationName;
	article2.Type = ArticleOptions.TableBased;

	// Set the required properties for the SalesOrderDetail article.
	article3.ConnectionContext = conn;
	article3.Name = articleName3;
	article3.DatabaseName = publicationDbName;
	article3.SourceObjectName = articleName3;
	article3.SourceObjectOwner = salesSchema;
	article3.PublicationName = publicationName;
	article3.Type = ArticleOptions.TableBased;

	if (!article1.IsExistingObject) article1.Create();
	if (!article2.IsExistingObject) article2.Create();
	if (!article3.IsExistingObject) article3.Create();

	// Select published columns for SalesOrderHeader.
	// Create an array of column names to vertically filter out.
	// In this example, only one column is removed.
	String[] columns = new String[1];

	columns[0] = "CreditCardApprovalCode";

	// Remove the column.
	article2.RemoveReplicatedColumns(columns);

	// Define a merge filter clauses that filter 
	// SalesOrderHeader based on Employee and 
	// SalesOrderDetail based on SalesOrderHeader. 

	// Parent article.
	filter12.JoinArticleName = articleName1;
	// Child article.
	filter12.ArticleName = articleName2;
	filter12.FilterName = filterName12;
	filter12.JoinUniqueKey = true;
	filter12.FilterTypes = FilterTypes.JoinFilter;
	filter12.JoinFilterClause = filterClause12;

	// Add the join filter to the child article.
	article2.AddMergeJoinFilter(filter12);

	// Parent article.
	filter23.JoinArticleName = articleName2;
	// Child article.
	filter23.ArticleName = articleName3;
	filter23.FilterName = filterName23;
	filter23.JoinUniqueKey = true;
	filter23.FilterTypes = FilterTypes.JoinFilter;
	filter23.JoinFilterClause = filterClause23;

	// Add the join filter to the child article.
	article3.AddMergeJoinFilter(filter23);
}
catch (Exception ex)
{
	// Do error handling here and rollback the transaction.
	throw new ApplicationException(
		"The filtered articles could not be created", ex);
}
finally
{
	conn.Disconnect();
}
' Define the Publisher and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"

' Specify article names.
Dim articleName1 As String = "Employee"
Dim articleName2 As String = "SalesOrderHeader"
Dim articleName3 As String = "SalesOrderDetail"

' Specify join filter information.
Dim filterName12 As String = "SalesOrderHeader_Employee"
Dim filterClause12 As String = "Employee.EmployeeID = " + _
    "SalesOrderHeader.SalesPersonID"
Dim filterName23 As String = "SalesOrderDetail_SalesOrderHeader"
Dim filterClause23 As String = "SalesOrderHeader.SalesOrderID = " + _
    "SalesOrderDetail.SalesOrderID"

Dim salesSchema As String = "Sales"
Dim hrSchema As String = "HumanResources"

Dim article1 As MergeArticle = New MergeArticle()
Dim article2 As MergeArticle = New MergeArticle()
Dim article3 As MergeArticle = New MergeArticle()
Dim filter12 As MergeJoinFilter = New MergeJoinFilter()
Dim filter23 As MergeJoinFilter = New MergeJoinFilter()

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

' Create three merge articles that are horizontally partitioned
' using a parameterized row filter on Employee.EmployeeID, which is 
' extended to the two other articles using join filters. 
Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Create each article. 
    ' For clarity, each article is defined separately. 
    ' In practice, iterative structures and arrays should 
    ' be used to efficiently create multiple articles.

    ' Set the required properties for the Employee article.
    article1.ConnectionContext = conn
    article1.Name = articleName1
    article1.DatabaseName = publicationDbName
    article1.SourceObjectName = articleName1
    article1.SourceObjectOwner = hrSchema
    article1.PublicationName = publicationName
    article1.Type = ArticleOptions.TableBased

    ' Define the parameterized filter clause based on Hostname.
    article1.FilterClause = "Employee.LoginID = HOST_NAME()"

    ' Set the required properties for the SalesOrderHeader article.
    article2.ConnectionContext = conn
    article2.Name = articleName2
    article2.DatabaseName = publicationDbName
    article2.SourceObjectName = articleName2
    article2.SourceObjectOwner = salesSchema
    article2.PublicationName = publicationName
    article2.Type = ArticleOptions.TableBased

    ' Set the required properties for the SalesOrderDetail article.
    article3.ConnectionContext = conn
    article3.Name = articleName3
    article3.DatabaseName = publicationDbName
    article3.SourceObjectName = articleName3
    article3.SourceObjectOwner = salesSchema
    article3.PublicationName = publicationName
    article3.Type = ArticleOptions.TableBased

    ' Create the articles, if they do not already exist.
    If article1.IsExistingObject = False Then
        article1.Create()
    End If
    If article2.IsExistingObject = False Then
        article2.Create()
    End If
    If article3.IsExistingObject = False Then
        article3.Create()
    End If

    ' Select published columns for SalesOrderHeader.
    ' Create an array of column names to vertically filter out.
    ' In this example, only one column is removed.
    Dim columns() As String = New String(0) {}

    columns(0) = "CreditCardApprovalCode"

    ' Remove the column.
    article2.RemoveReplicatedColumns(columns)

    ' Define a merge filter clauses that filter 
    ' SalesOrderHeader based on Employee and 
    ' SalesOrderDetail based on SalesOrderHeader. 

    ' Parent article.
    filter12.JoinArticleName = articleName1
    ' Child article.
    filter12.ArticleName = articleName2
    filter12.FilterName = filterName12
    filter12.JoinUniqueKey = True
    filter12.FilterTypes = FilterTypes.JoinFilter
    filter12.JoinFilterClause = filterClause12

    ' Add the join filter to the child article.
    article2.AddMergeJoinFilter(filter12)

    ' Parent article.
    filter23.JoinArticleName = articleName2
    ' Child article.
    filter23.ArticleName = articleName3
    filter23.FilterName = filterName23
    filter23.JoinUniqueKey = True
    filter23.FilterTypes = FilterTypes.JoinFilter
    filter23.JoinFilterClause = filterClause23

    ' Add the join filter to the child article.
    article3.AddMergeJoinFilter(filter23)

Catch ex As Exception
    ' Do error handling here and rollback the transaction.
    Throw New ApplicationException( _
        "The filtered articles could not be created", ex)
Finally
    conn.Disconnect()
End Try

참고 항목See Also

게시 만들기 Create a Publication
복제 시스템 저장 프로시저 개념 Replication System Stored Procedures Concepts
기존 게시에 대한 아티클 추가 및 삭제 Add Articles to and Drop Articles from Existing Publications
게시된 데이터 필터링 Filter Published Data
데이터 및 데이터베이스 개체 게시 Publish Data and Database Objects
복제 시스템 저장 프로시저 개념 Replication System Stored Procedures Concepts