적용 대상:SQL Server
이 글은 SQL Server Management Studio, Transact-SQL, 또는 복제 관리 객체(RMO)를 사용하여 SQL Server에서 문서를 정의하는 방법을 설명합니다.
문서 내용
시작하기 전 주의 사항:
문서를 정의하려면 다음을 사용하세요:
시작하기 전에
제한 사항
- 문서 이름에는 다음 문자를 포함할 수 없습니다: %, * , [ , ] , | , : , " , ? , ' , \ , / , < , >. 데이터베이스 내 객체에 이러한 문자들이 포함되어 있고 복제하고 싶다면, 객체 이름과 다른 문서 이름을 지정해야 합니다.
보안
가능한 경우 런타임 시 사용자에게 보안 자격 증명을 입력하라는 메시지가 표시됩니다. 자격 증명을 저장해야 하는 경우 Microsoft Windows .NET Framework에서 제공하는 암호화 서비스를 사용합니다.
SQL Server Management Studio 사용
새 출판 마법사를 사용해 출판물을 만들고 문서를 정의하세요. 출판물을 생성한 후, 출판물 속성 - <출판물> 대화상자에서 출판물 속성을 보고 수정하세요. Oracle 데이터베이스에서 게시를 만드는 방법에 대한 자세한 내용은 Oracle Database에서 게시 만들기를 참조하세요.
게시를 만들고 아티클을 정의하려면
Microsft SQL Server Management Studio에서 게시자에 연결한 다음 해당 서버 노드를 확장합니다.
복제 폴더를 확장한 다음 로컬 게시 폴더를 마우스 오른쪽 단추로 클릭합니다.
새 게시를 클릭합니다.
New Publication Wizard의 페이지를 따라가세요:
서버에서 배포를 설정하지 않았다면 배포자를 지정하세요. 배포 구성에 대한 자세한 내용은 게시 및 배포 구성을 참조하세요.
Distributor 페이지에서 Publisher 서버가 자체 Distributor(로컬 Distributor)로 동작한다고 지정하고, 서버가 Distributor로 설정되어 있지 않으면, New Publication Wizard가 서버를 구성합니다. Snapshot Folder 페이지에서 배포자의 기본 스냅샷 폴더를 지정하세요. 스냅샷 폴더는 공유로 지정한 디렉터리입니다. 이 폴더에서 읽고 쓰는 에이전트는 이 폴더에 접근할 수 있는 충분한 권한을 가져야 합니다. 폴더의 적절한 보안 유지 방법에 대한 자세한 내용은 스냅샷 폴더 보안 설정을 참조하세요.
다른 서버가 배포자 역할을 하도록 지정하면, Publisher에서 배포자로 연결될 때 관리자 비밀번호 페이지에 비밀번호를 입력하세요. 이 비밀번호는 원격 배포자에서 Publisher를 활성화할 때 지정한 비밀번호와 일치해야 합니다.
자세한 내용은 배포 구성을 참조하세요.
게시 데이터베이스를 선택합니다.
보고서 유형을 선택합니다. 자세한 내용은 복제 형식을 참조하세요.
게시할 데이터와 데이터베이스 객체를 지정하세요. 선택적으로, 테이블 문서의 열을 필터링하고 문서 속성을 설정하세요.
필요에 따라 테이블 아티클에서 행을 필터링합니다. 자세한 정보는 게시된 데이터 필터링을 참조하세요.
스냅샷 에이전트 일정을 설정합니다.
다음 복제 에이전트가 실행 및 연결에 사용하는 자격 증명을 지정합니다.
- 모든 게시를 위한 스냅샷 에이전트.
- 모든 트랜잭션 게시용 로그 판독기 에이전트
- 업데이트 가능한 구독을 허용하는 트랜잭션 게시용 큐 리더 에이전트
자세한 내용은 복제 에이전트 보안 모델 및 복제 보안 모범 사례를 참조하세요.
필요에 따라 게시 작업을 스크립트로 작성합니다. 자세한 내용은 복제 스크립팅을 참조하세요.
게시의 이름을 지정합니다.
Transact-SQL 사용
출판물을 생성한 후에는 복제 저장 프로시저를 사용해 프로그래밍적으로 기사를 작성하세요. 문서 생성을 위한 저장 절차는 문서의 출판 유형에 따라 다릅니다. 자세한 내용은 게시물 만들기를 참조하세요.
스냅샷 또는 트랜잭션 게시에 대한 아티클을 정의하려면
게시 데이터베이스의 게시자에서 sp_addarticle을 실행합니다. 해당 논문이 속
@publication한 출판물명, 논문@article이름, 게시할@source_object데이터베이스 객체, 그리고 기타 선택적 매개변수를 지정하세요.@source_owner가 아닌 경우 를 사용하여 개체의 스키마 소유권을 지정합니다. 만약 문서가 로그 기반 표 문서가 아니라면, 에 대해@type문서 유형을 지정하세요. 자세한 내용은 아티클 형식 지정(복제 Transact-SQL 프로그래밍)을 참조하세요.테이블이나 뷰에서 행을 가로로 필터링하거나 아티클을 보려면 sp_articlefilter를 사용하여 필터 절을 정의합니다. 자세한 내용은 정적 행 필터 정의 및 수정을 참조하세요.
테이블 또는 뷰의 열을 세로로 필터링하거나 아티클을 확인하려면 sp_articlecolumn을 사용합니다. 자세한 내용은 열 필터 정의 및 수정을 참조하세요.
아티클이 필터링되면 sp_articleview를 실행합니다.
게시에 기존 구독이 있고 sp_helppublication이 immediate_sync 열에서 0 값을 반환하는 경우 sp_addsubscription 호출하여 각 기존 구독에 아티클을 추가해야 합니다.
게시물에 기존 끌어오기 구독이 있는 경우, 기존 끌어오기 구독에 대해 새 아티클만 포함하는 새 스냅샷을 만들려면 게시자에서 sp_refreshsubscriptions를 실행합니다.
참고
스냅샷을 사용해 초기화되지 않은 구독의 경우, sp_refreshsubscriptions 실행할 필요가 없습니다. 왜냐하면 sp_addarticle 이 절차를 실행하기 때문입니다.
병합 게시에 대한 아티클을 정의하려면
게시 데이터베이스의 게시자에서 sp_addmergearticle을 실행합니다.
@publication의 출판물 이름,@article의 문서 이름, 그리고@source_object에 게시할 객체를 지정하세요. 테이블 행을 가로로 필터링하려면@subset_filterclause에 값을 지정합니다. 자세한 내용은 병합 아티클에 대한 매개 변수가 있는 행 필터 정의 및 수정과 정적 행 필터 정의 및 수정을 참조하세요. 만약 해당 문서가 테이블 문서가 아니라면, 에 대해@type문서 유형을 지정하세요. 자세한 내용은 아티클 형식 지정(복제 Transact-SQL 프로그래밍)을 참조하세요.(선택 사항) 게시 데이터베이스의 게시자에서 sp_addmergefilter를 실행하여 두 아티클 사이에서 조인 필터를 정의합니다. 자세한 내용은 병합 문서 사이에서 조인 필터 정의 및 수정을 참조하세요.
(선택 사항) 게시 데이터베이스의 게시자에서 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.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(복제 관리 개체) 사용
RMO(복제 관리 개체)를 사용하여 프로그래밍 방식으로 아티클을 정의할 수 있습니다. 아티클을 정의하는 데 사용하는 RMO 클래스는 아티클이 정의된 게시 유형에 따라 달라집니다.
예제 (RMO)
다음 예제에서는 트랜잭션 게시에 행 및 열 필터가 있는 아티클을 추가합니다.
// Define the Publisher, publication, and article names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2022";
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 = "AdventureWorks2022"
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
다음 예에서는 병합 게시에 세 개의 아티클을 추가합니다. 아티클에는 열 필터가 있으며 두 개의 조인 필터를 사용하여 매개 변수가 있는 행 필터를 다른 아티클로 전파합니다.
// Define the Publisher and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2022";
// 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 = "AdventureWorks2022"
' 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