sp_articlefilter (Transact-SQL)

基于表项目筛选发布的数据。此存储过程在发布服务器上针对发布数据库执行。

主题链接图标Transact-SQL 语法约定

语法

sp_articlefilter [ @publication = ] 'publication'
        , [ @article = ] 'article'
    [ , [ @filter_name = ] 'filter_name' ]
    [ , [ @filter_clause = ] 'filter_clause' ]
    [ , [ @force_invalidate_snapshot = ] force_invalidate_snapshot ]
    [ , [ @force_reinit_subscription = ] force_reinit_subscription ]
    [ , [ @publisher = ] 'publisher' ]

参数

  • [ @publication = ] 'publication'
    包含项目的发布的名称。publication 的数据类型为 sysname,无默认值。
  • [ @article = ] 'article'
    项目的名称。article 的数据类型为 sysname,无默认值。
  • [ @filter_name=] 'filter_name'
    要从 filter_name 创建的筛选存储过程的名称。filter_name 的数据类型为 nvarchar(386),默认值为 NULL。您必须为项目筛选指定唯一的名称。
  • [ @filter_clause=] 'filter_clause'
    定义水平筛选器的限制 (WHERE) 子句。当输入限制子句时,将省略关键字 WHERE。filter_clause 的数据类型为 ntext,默认值为 NULL。
  • [ @force_invalidate_snapshot = ] force_invalidate_snapshot
    确认此存储过程所执行的操作可能会使现有快照失效。force_invalidate_snapshot 的数据类型为 bit,默认值为 0

    0 指定对项目所做的更改不会导致快照失效。如果该存储过程检测到更改确实需要新的快照,则会发生错误,并且不执行任何更改。

    1 指定对项目所做的更改可能会导致快照失效,如果存在需要新快照的现有订阅,则向其授予将现有快照标记为过时并生成新快照的权限。

  • [ @force_reinit_subscription = ] force_reinit_subscription
    确认此存储过程所执行的操作是否需要重新初始化现有订阅。force_reinit_subscription 的数据类型为 bit,默认值为 0

    0 指定对项目所做的更改不会导致重新初始化订阅。如果该存储过程检测到更改将需要重新初始化订阅,则会发生错误,并且不执行任何更改。

    1 指定对项目所做的更改可导致重新初始化现有的订阅,并且授予重新初始化订阅的权限。

  • [ @publisher= ] 'publisher'
    指定一个非 Microsoft SQL Server 发布服务器。publishersysname,默认值为 NULL。

    ms178558.note(zh-cn,SQL.90).gif注意:
    publisher 不应与 SQL Server 发布服务器一起使用。

返回代码值

0(成功)或 1(失败)

备注

sp_articlefilter 用于快照复制和事务性复制。

通过现有订阅针对项目执行 sp_articlefilter 需要重新初始化这些订阅。

sp_articlefilter 创建筛选,在 sysarticles (Transact-SQL) 表的 filter 列中插入筛选存储过程的 ID,然后在 filter_clause 列中插入限制子句的文本。

若要创建具有水平筛选的项目,请在不使用 filter 参数的情况下执行 sp_addarticle (Transact-SQL)。执行 sp_articlefilter,并提供包括 filter_clause 的所有参数,然后执行 sp_articleview (Transact-SQL),并提供包括相同 filter_clause 的所有参数。如果该筛选已存在,而且 sysarticles 中的 type1(基于日志的项目),则删除以前的筛选并创建新筛选。

如果未提供 filter_namefilter_clause,则删除以前的筛选并将筛选 ID 设置为 0

权限

只有 sysadmin 固定服务器角色成员或 db_owner 固定数据库角色成员才能执行 sp_articlefilter

示例

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

请参阅

参考

sp_addarticle (Transact-SQL)
sp_articleview (Transact-SQL)
sp_changearticle (Transact-SQL)
sp_droparticle (Transact-SQL)
sp_helparticle (Transact-SQL)
复制存储过程 (Transact-SQL)

其他资源

How to: Define an Article (Replication Transact-SQL Programming)
How to: Define and Modify a Static Row Filter (Replication Transact-SQL Programming)

帮助和信息

获取 SQL Server 2005 帮助