sp_articlefilter (Transact-SQL)
适用于: SQL Server
Azure SQL 托管实例
筛选基于表项目发布的数据。 此存储过程在发布服务器上对发布数据库执行。
语法
sp_articlefilter
[ @publication = ] N'publication'
, [ @article = ] N'article'
[ , [ @filter_name = ] N'filter_name' ]
[ , [ @filter_clause = ] N'filter_clause' ]
[ , [ @force_invalidate_snapshot = ] force_invalidate_snapshot ]
[ , [ @force_reinit_subscription = ] force_reinit_subscription ]
[ , [ @publisher = ] N'publisher' ]
[ ; ]
参数
[ @publication = ] N'publication'
包含项目的发布的名称。 @publication 为 sysname,无默认值。
[ @article = ] N'article'
项目的名称。 @article 为 sysname,无默认值。
[ @filter_name = ] N'filter_name'
要从 @filter_name创建的筛选器存储过程的名称。 @filter_name为 nvarchar(517),默认值为 NULL
. 您必须为项目筛选指定唯一的名称。
[ @filter_clause = ] N'filter_clause'
定义水平筛选器的限制 (WHERE
) 子句。 输入限制子句时,省略关键字 WHERE
。 @filter_clause 为 nvarchar(max),默认值为 NULL
.
[ @force_invalidate_snapshot = ] force_invalidate_snapshot
确认此存储过程执行的操作可能会使现有快照失效。 @force_invalidate_snapshot为位,默认值为 0
.
0
指定对项目所做的更改不会导致快照无效。 如果该存储过程检测到更改确实需要新的快照,则会发生错误,并且不进行任何更改。1
指定对项目所做的更改可能会导致快照无效,如果存在需要新快照的现有订阅,则授予现有快照标记为已过时和生成的新快照的权限。
[ @force_reinit_subscription = ] force_reinit_subscription
确认此存储过程所执行的操作是否需要重新初始化现有订阅。 @force_reinit_subscription为位,默认值为 0
.
0
指定对项目所做的更改不会导致重新初始化订阅的需要。 如果该存储过程检测到更改将需要重新初始化订阅,则会发生错误,并且不进行任何更改。1
指定对项目所做的更改会导致现有订阅重新初始化,并授予订阅重新初始化的权限。
[ @publisher = ] N'publisher'
指定非 SQL Server 发布服务器。 @publisher为 sysname,默认值为 NULL
.
@publisher 不应与 SQL Server 发布服务器一起使用。
返回代码值
0
(成功)或 1
(失败)。
注解
sp_articlefilter
用于快照复制和事务复制。
对具有现有订阅的项目执行 sp_articlefilter
要求重新初始化这些订阅。
sp_articlefilter
创建筛选器,在 sysarticles 表的列中插入筛选器存储过程filter
的 ID,然后在列中插入限制子句filter_clause
的文本。
若要创建具有水平筛选器的文章,请执行不带@filter_name参数的sp_addarticle。 执行sp_articlefilter
,提供包括@filter_clause在内的所有参数,然后执行sp_articleview,并提供所有参数,包括相同的@filter_clause。 如果筛选器已存在,并且该筛选器是 type
sysarticles
1
(基于日志的文章),则会删除上一个筛选器,并创建一个新筛选器。
如果未 提供@filter_name 和 @filter_clause ,则会删除上一个筛选器,并将筛选器 ID 设置为 0
。
示例
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
权限
只有 sysadmin 固定服务器角色的成员或db_owner固定数据库角色的成员才能执行sp_articlefilter
。