Definizione di un articoloDefine an Article

In questo argomento viene descritto come definire un articolo in SQL Server 2017SQL Server 2017 tramite SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQLo RMO (Replication Management Objects).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).

Contenuto dell'argomentoIn This Topic

Prima di iniziare Before You Begin

Limitazioni e restrizioni Limitations and Restrictions

  • I nomi di articolo non possono includere i caratteri seguenti: %, *, [,], |: ?"Article names cannot include any of the following characters: % , * , [ , ] , | , : , " , ? , ' , \ , / , < , >., ' , \ , / , < , >. Se si desidera replicare oggetti del database che includono uno qualsiasi di questi caratteri, è necessario specificare un nome di articolo diverso dal nome dell'oggetto.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.

Sicurezza Security

Se possibile, richiedere agli utenti di immettere le credenziali di sicurezza in fase di esecuzione.When possible, prompt users to enter security credentials at runtime. Se è necessario archiviare le credenziali, utilizzare i servizi di crittografia offerti da MicrosoftMicrosoft Windows .NET Framework.If you must store credentials, use the cryptographic services provided by the MicrosoftMicrosoft Windows .NET Framework.

Utilizzo di SQL Server Management Studio Using SQL Server Management Studio

Creare le pubblicazioni e definire gli articoli utilizzando la Creazione guidata nuova pubblicazione.Create publications and define articles with the New Publication Wizard. Dopo aver creato una pubblicazione, visualizzare e modificare le proprietà della stessa nella finestra di dialogo Proprietà pubblicazione - <Pubblicazione>.After a publication is created, view and modify publication properties in the Publication Properties - <Publication> dialog box. Per informazioni sulla creazione di una pubblicazione da un database Oracle, vedere Creare una pubblicazione da un database Oracle.For information about creating a publication from an Oracle database, see Create a Publication from an Oracle Database.

Per creare una pubblicazione e definire articoliTo create a publication and define articles

  1. Connettersi al server di pubblicazione in MicrosoftMicrosoft SQL Server Management StudioSQL Server Management Studioe quindi espandere il nodo del server.Connect to the Publisher in MicrosoftMicrosoft SQL Server Management StudioSQL Server Management Studio, and then expand the server node.

  2. Espandere la cartella Replica e quindi fare clic con il pulsante destro del mouse sulla cartella Pubblicazioni locali .Expand the Replication folder, and then right-click the Local Publications folder.

  3. Fare clic su Nuova pubblicazione.Click New Publication.

  4. Eseguire i vari passaggi della Creazione guidata nuova pubblicazione per:Follow the pages in the New Publication Wizard to:

    • Specificare un server di distribuzione se la distribuzione non è stata configurata sul server.Specify a Distributor if distribution has not been configured on the server. Per altre informazioni sulla configurazione della distribuzione, vedere Configurare la pubblicazione e la distribuzione.For more information about configuring distribution, see Configure Publishing and Distribution.

      Se nella pagina Server di distribuzione si specifica che il server di pubblicazione deve agire come server di distribuzione per se stesso (server di distribuzione locale) e il server non è configurato come server di distribuzione, la Creazione guidata nuova pubblicazione eseguirà la configurazione del server.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. Nella pagina Cartella snapshot è necessario specificare una cartella snapshot predefinita per il server di distribuzione.You will specify a default snapshot folder for the Distributor on the Snapshot Folder page. La cartella snapshot è semplicemente una directory designata come condivisione. Gli agenti che eseguono letture e scritture in questa cartella devono disporre di autorizzazioni sufficienti per accedervi.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. Per altre informazioni sulle impostazioni di sicurezza appropriate per la cartella, vedere Proteggere la cartella snapshot.For more information about securing the folder appropriately, see Secure the Snapshot Folder.

      Se si specifica che un altro server deve agire come server di distribuzione, è necessario immettere una password nella pagina Password amministrativa per le connessioni effettuate dal server di pubblicazione a quello di distribuzione.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. Questa password deve corrispondere a quella specificata quando il server di pubblicazione è stato attivato nel server di distribuzione remoto.This password must match the password specified when the Publisher was enabled at the remote Distributor.

      Per altre informazioni, vedere Configure Distribution.For more information, see Configure Distribution.

    • Scegliere un database di pubblicazione.Choose a publication database.

    • Selezionare un tipo di pubblicazione.Select a publication type. Per altre informazioni, vedere Tipi di replica.For more information, see Types of Replication.

    • Specificare i dati e gli oggetti di database da pubblicare; facoltativamente, filtrare le colonne dagli articoli di tabelle e impostare le proprietà degli articoli.Specify data and database objects to publish; optionally filter columns from table articles, and set article properties.

    • Facoltativamente, filtrate le righe dagli articoli di tabelle.Optionally filter rows from table articles. Per altre informazioni, vedere Filtrare i dati pubblicati.For more information, see Filter Published Data.

    • Impostare la pianificazione dell'agente snapshot.Set the Snapshot Agent schedule.

    • Specificare le credenziali con cui gli agenti di replica seguenti vengono eseguiti e stabiliscono le connessioni:Specify the credentials under which the following replication agents run and make connections:

      - Agente snapshot per tutte le pubblicazioni.- Snapshot Agent for all publications.

      - Agente di lettura log per tutte le pubblicazioni transazionali.- Log Reader Agent for all transactional publications.

      - Agente di lettura coda per le pubblicazioni transazionali che consentono l'aggiornamento delle sottoscrizioni.- Queue Reader Agent for transactional publications that allow updating subscriptions.

      Per ulteriori informazioni, vedere Replication Agent Security Model e Replication Security Best Practices.For more information, see Replication Agent Security Model and Replication Security Best Practices.

    • Facoltativamente, creare lo script della pubblicazione.Optionally script the publication. Per altre informazioni, vedere Scripting Replication.For more information, see Scripting Replication.

    • Specificare un nome per la pubblicazione.Specify a name for the publication.

Utilizzo di Transact-SQL Using Transact-SQL

Dopo aver creato una pubblicazione, è possibile creare gli articoli a livello di programmazione tramite le codice stored procedure di replica.After a publication has been created, articles can be created programmatically using replication stored procedures. Le stored procedure utilizzate per creare un articolo dipendono dal tipo di pubblicazione per il quale viene definito l'articolo.The stored procedures used to create an article will depend on the type of publication for which the article is being defined. Per altre informazioni, vedere Create a Publication.For more information, see Create a Publication.

Per definire un articolo per una pubblicazione snapshot o transazionaleTo define an article for a Snapshot or Transactional Publication

  1. Nel database di pubblicazione del server di pubblicazione eseguire sp_addarticle.At the Publisher on the publication database, execute sp_addarticle. Specificare il nome della pubblicazione cui appartiene l'articolo per @publication, il nome dell'articolo per @article, l'oggetto di database da pubblicare per @source_objected eventuali altri parametri facoltativi.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. Utilizzare @source_owner per specificare la proprietà dello schema dell'oggetto, se diversa da dbo.Use @source_owner to specify the schema ownership of the object, if not dbo. Se l'articolo non è un articolo di tabella basato su log, specificare il tipo di articolo per @type. Per altre informazioni, vedere Specificare i tipi di articolo (programmazione Transact-SQL della replica).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. Per filtrare in senso orizzontale le righe di una tabella o visualizzare un articolo, utilizzare sp_articlefilter per definire la clausola di filtro.To horizontally filter rows in a table or view an article, use sp_articlefilter to define the filter clause. Per altre informazioni, vedere Define and Modify a Static Row Filter.For more information, see Define and Modify a Static Row Filter.

  3. Per filtrare in senso verticale le colonne di una tabella o visualizzare un articolo, utilizzare sp_articlecolumn.To vertically filter columns in a table or view an article, use sp_articlecolumn. Per altre informazioni, vedere Define and Modify a Column Filter.For more information, see Define and Modify a Column Filter.

  4. Eseguire sp_articleview se l'articolo è filtrato.Execute sp_articleview if the article is filtered.

  5. Se per la pubblicazione esistono sottoscrizioni e sp_helppublication restituisce il valore 0 nella colonna immediate_sync , è necessario chiamare sp_addsubscription per aggiungere l'articolo a ogni sottoscrizione esistente.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. Se per la pubblicazione esistono sottoscrizioni pull, eseguire sp_refreshsubscriptions nel server di pubblicazione per creare un nuovo snapshot per le sottoscrizioni pull esistenti contenente solo il nuovo articolo.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.

    Nota

    Per le sottoscrizioni non inizializzate tramite snapshot, non è necessario eseguire sp_refreshsubscriptions poiché tale procedura viene eseguita da 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.

Per definire un articolo per una pubblicazione di tipo mergeTo define an article for a Merge Publication

  1. Nel database di pubblicazione del server di pubblicazione eseguire sp_addmergearticle.At the Publisher on the publication database, execute sp_addmergearticle. Specificare il nome della pubblicazione per @publication, il nome dell'articolo per @articlee l'oggetto da pubblicare per @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. Per filtrare in senso orizzontale le righe della tabella, specificare un valore per @subset_filterclause.To horizontally filter table rows, specify a value for @subset_filterclause. Per ulteriori informazioni, vedere Define and Modify a Parameterized Row Filter for a Merge Article e Define and Modify a Static Row Filter.For more information, see Define and Modify a Parameterized Row Filter for a Merge Article and Define and Modify a Static Row Filter. Se l'articolo non è un articolo di tabella, specificare il tipo di articolo per @type.If the article is not a table article, specify the article type for @type. Per altre informazioni, vedere Specificare i tipi di articolo (programmazione Transact-SQL della replica).For more information, see Specify Article Types (Replication Transact-SQL Programming).

  2. (Facoltativo) Nel database di pubblicazione del server di pubblicazione eseguire sp_addmergefilter per definire un filtro di join tra due articoli.(Optional) At the Publisher on the publication database, execute sp_addmergefilter to define a join filter between two articles. Per altre informazioni, vedere Define and Modify a Join Filter Between Merge Articles.For more information, see Define and Modify a Join Filter Between Merge Articles.

  3. (Facoltativo) Nel database di pubblicazione del server di pubblicazione eseguire sp_mergearticlecolumn per filtrare le colonne della tabella.(Optional) At the Publisher on the publication database, execute sp_mergearticlecolumn to filter table columns. Per altre informazioni, vedere Define and Modify a Column Filter.For more information, see Define and Modify a Column Filter.

Esempi (Transact-SQL) Examples (Transact-SQL)

In questo esempio si definisce un articolo basato sulla tabella Product per una pubblicazione transazionale, in cui l'articolo è filtrato in senso orizzontale e verticale.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

In questo esempio si definiscono gli articoli per una pubblicazione di tipo merge, in cui l'articolo SalesOrderHeader è filtrato in modo statico in base a SalesPersonIDe l'articolo SalesOrderDetail è filtrato con filtro di join in base a 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

Utilizzo di RMO (Replication Management Objects) Using Replication Management Objects (RMO)

È possibile definire articoli a livello di programmazione tramite gli oggetti RMO (Replication Management Objects).You can define articles programmatically by using Replication Management Objects (RMO). Le classi RMO utilizzate per la definizione di un articolo dipendono dal tipo di pubblicazione per la quale l'articolo viene definito.The RMO classes that you use to define an article depend on the type of publication for which the article is defined.

Esempi (RMO) Examples (RMO)

Nell'esempio seguente un articolo con filtri di riga e di colonna viene aggiunto a una pubblicazione transazionale.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

Nell'esempio seguente tre articoli vengono aggiunti a una pubblicazione di tipo merge.The following example adds three articles to a merge publication. Gli articoli contengono filtri di colonna e vengono utilizzati due filtri join per propagare un filtro di riga con parametri negli altri articoli.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

Vedere ancheSee Also

Creare una pubblicazione Create a Publication
Concetti di base relativi alle stored procedure del sistema di replica Replication System Stored Procedures Concepts
Aggiungere ed eliminare articoli in pubblicazioni esistenti Add Articles to and Drop Articles from Existing Publications
Filtrare i dati pubblicati Filter Published Data
Pubblicare dati e oggetti di database Publish Data and Database Objects
Concetti di base relativi alle stored procedure del sistema di replicaReplication System Stored Procedures Concepts