生成筛选器Generate Filters

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

使用 “生成筛选器” 对话框,可以对合并发布中某一个表定义行筛选器;然后,复制会自动将筛选器扩展到通过外键关系相关的其他表。The Generate Filters dialog box allows you to define a row filter on one table in a merge publication; replication then automatically extends the filter to other tables that are related through foreign key relationships. 例如,如果对 Customer 表定义筛选器,使其仅包含与法国客户有关的数据,则复制将扩展该筛选器,以便相关的 Orders 表和 Order Details 表仅包含与法国客户相关的信息。For example, if you define a filter on a customer table so that it only contains data on French customers, replication extends that filter so that related orders and order details tables contain only information related to French customers.

选项Options

使用此对话框可以创建表的行筛选器,包括三个步骤。This dialog box involves a three-step process to create a row filter on a table. 然后,将筛选器扩展到与筛选的表通过主键和外键关系相关的表。The filter is then extended to the tables related to the filtered table through primary key and foreign key relationships. 例如,假设有三个表: CustomerSalesOrderHeaderSalesOrderDetail,其中 Customer 表与 SalesOrderHeader 表之间有关系, SalesOrderHeader 表与 SalesOrderDetail 表之间有关系,将行筛选器应用于 Customer 表,则复制会将该筛选器扩展到 SalesOrderHeader 表和 SalesOrderDetail 表。For example, given the three tables Customer, SalesOrderHeader, and SalesOrderDetail, with a relationship between Customer and SalesOrderHeader, and a relationship between SalesOrderHeader and SalesOrderDetail, apply a row filter to Customer, and replication extends that filter to SalesOrderHeader and SalesOrderDetail.

  1. 选择要筛选的表。Select the table to filter.

    从下拉列表框中选择表。Select a table from the drop-down list box. 只有在 “项目” 页上所选择的表才会出现在列表框中。Tables appear in the list box only if they were selected on the Articles page.

  2. 完成筛选语句以标识订阅服务器所要接收的表行。Complete the filter statement to identify which table rows Subscribers will receive.

    定义新的筛选语句。Define a new filter statement. “列” 列表框列出了要从 “选择要筛选的表” 中选择的表中发布的所有列。The Columns list box lists all the columns that you are publishing from the table you selected in Select the table to filter. “筛选语句” 文本区域包括默认的文本,其格式为:The Filter statement text area includes the default text, which is in the form of:

    SELECT <published_columns> FROM [tableowner].[tablename] WHERE

    此文本无法更改;请使用标准的 Transact-SQLTransact-SQL 语法在 WHERE 关键字后键入筛选子句。This text cannot be changed; type the filter clause after the WHERE keyword using standard Transact-SQLTransact-SQL syntax.

    重要

    为提高性能,建议您不要在参数化行筛选子句中对列名应用函数,如 LEFT([MyColumn]) = SUSER_SNAME()For performance reasons, we recommended that you not apply functions to column names in parameterized row filter clauses, such as LEFT([MyColumn]) = SUSER_SNAME(). 如果在筛选子句中使用 HOST_NAME 并覆盖 HOST_NAME 值,则可能需要使用 CONVERT 转换数据类型。If you use HOST_NAME in a filter clause and override the HOST_NAME value, it might be necessary to convert data types using CONVERT. 有关此情况的最佳实践的详细信息,请参阅主题 Parameterized Row Filters中的“覆盖 HOST_NAME() 值”一节。For more information about best practices for this case, see the section "Overriding the HOST_NAME() Value" in the topic Parameterized Row Filters.

  3. 指定将从此表接收数据的订阅数。Specify how many subscriptions will receive data from this table.

    仅限 MicrosoftMicrosoft SQL Server 2005 (9.x)SQL Server 2005 (9.x) 及更高版本。MicrosoftMicrosoft SQL Server 2005 (9.x)SQL Server 2005 (9.x) and later versions only. 通过合并复制,可以指定最适合您的数据和应用程序的分区类型。Merge replication allows you to specify the type of partitions that are best suited to your data and application. 如果选择 “此表中的行将仅转到一个订阅”,则合并复制将设置不重叠分区选项。If you select A row from this table will go to only one subscription, merge replication sets the nonoverlapping partitions option. 不重叠分区与预计算分区协同工作以提高性能,使用不重叠分区可以将与预计算分区相关联的上载开销降至最低。Nonoverlapping partitions work in conjunction with precomputed partitions to improve performance, with nonoverlapping partitions minimizing the upload cost associated with precomputed partitions. 使用的参数化筛选器和联接筛选器越复杂,不重叠分区的性能优势就越明显。The performance benefit of nonoverlapping partitions is more noticeable when the parameterized filters and join filters used are more complex. 如果选择此选项,则必须确保对数据分区时不能将行复制到多个订阅服务器。If you select this option, you must ensure that the data is partitioned in such a way that a row cannot be replicated to more than one Subscriber. 有关详细信息,请参阅主题 参数化行筛选器中的“设置‘分区选项’”部分。For more information, see the section "Setting 'partition options'" in the topic Parameterized Row Filters.

添加筛选器之后,请单击 “确定” 退出并关闭该对话框。After you have added a filter, click OK to exit and close the dialog box. 将对照 SELECT 子句中的表分析并运行指定的筛选器。The filter you specified is parsed and run against the table in the SELECT clause. 如果筛选语句有语法错误或其他问题,将会通知您编辑该筛选语句。If the filter statement contains syntax errors or other problems, you will be notified and will be able to edit the filter statement.

分析该语句之后,复制将创建必要的联接筛选器。After the statement is parsed, replication creates the necessary join filters. 如果您尚未对运行此向导的发布服务器配置分发服务器,系统将会提示您进行配置。If you have not yet configured the Distributor for the Publisher against which this wizard is running, you are prompted to configure it.

另请参阅See Also

Create a Publication Create a Publication
查看和修改发布属性 View and Modify Publication Properties
筛选已发布数据 Filter Published Data
Join Filters Join Filters
Parameterized Row Filters Parameterized Row Filters
发布数据和数据库对象Publish Data and Database Objects