sp_articleview (Transact-SQL)

在垂直或水平筛选表时创建用于定义已发布项目的视图。该视图用作目标表的架构和数据的筛选源。只有未订阅的项目才能由此存储过程修改。此存储过程在发布服务器上对发布数据库执行。

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

语法

sp_articleview [ @publication = ] 'publication'
        , [ @article = ] 'article'
    [ , [ @view_name = ] 'view_name']
    [ , [ @filter_clause = ] 'filter_clause']
    [ , [ @change_active = ] change_active ]
    [ , [ @force_invalidate_snapshot = ] force_invalidate_snapshot ]
    [ , [ @force_reinit_subscription = ] force_reinit_subscription ]
    [ , [ @publisher = ] 'publisher' ]
    [ , [ @refreshsynctranprocs = ] refreshsynctranprocs ]
    [ , [ @internal = ] internal ]

参数

  • [ @publication=] 'publication'
    包含该项目的发布的名称。publication 的数据类型为 sysname,无默认值。
  • [ @article = ] 'article'
    项目的名称。article 的数据类型为 sysname,无默认值。
  • [ @view_name=] 'view_name'
    定义已发布项目的视图的名称。view_name 的数据类型为 nvarchar(386),默认值为 NULL。
  • [ @filter_clause=] 'filter_clause'
    定义水平筛选器的限制 (WHERE) 子句。当输入限制子句时,省略 WHERE 关键字。filter_clause 的数据类型为 ntext,默认值为 NULL。
  • [ @change_active = ] change_active
    允许修改具有订阅的发布中的列。change_active 的数据类型为 int,默认值为 0。如果为 0,则不更改列。如果为 1,则可以为具有订阅的活动项目创建或重新创建视图。
  • [ @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 发布服务器。publisher 的数据类型为 sysname,默认值为 NULL。

    ms187790.note(zh-cn,SQL.90).gif注意:
    从 SQL Server 发布服务器进行发布时,不应使用 publisher
  • [ @refreshsynctranprocs = ] refreshsynctranprocs
    指示是否自动重新创建用于同步复制的存储过程。refreshsynctranprocs 的数据类型为 bit,默认值为 1。

    1 表示重新创建该存储过程。

    0 表示不重新创建该存储过程。

  • [ @internal= ] internal
    仅限内部使用。

返回代码值

0(成功)或 1(失败)

备注

sp_articleview 创建用于定义已发布项目的视图并在 sysarticles (Transact-SQL) 表的 sync_objid 列中插入该视图的 ID,在 filter_clause 列中插入限制子句的文本。如果所有列均已复制并且没有 filter_clause,则 sysarticles (Transact-SQL) 表中的 sync_objid 设置为基表的 ID,并且无需使用 sp_articleview

若要发布垂直筛选的表(即筛选列),请首先在不使用 sync_object 参数的情况下运行 sp_addarticle,为要复制的每一列都运行一次 sp_articlecolumn (Transact-SQL)(定义垂直筛选),然后运行 sp_articleview 创建用于定义已发布项目的视图。

若要发布水平筛选的表(即筛选行),请在不使用 filter 参数的情况下运行 sp_addarticle (Transact-SQL)。接着运行 sp_articlefilter (Transact-SQL),并提供包括 filter_clause 在内的全部参数。然后运行 sp_articleview,并提供包括相同的 filter_clause 在内的全部参数。

若要发布垂直筛选和水平筛选的表,请在不使用 sync_object 参数或 filter 参数的情况下运行 sp_addarticle (Transact-SQL)。对要复制的每列运行一次 sp_articlecolumn (Transact-SQL),然后运行 sp_articlefilter (Transact-SQL)sp_articleview

如果项目已具有用于定义已发布项目的视图,则 sp_articleview 删除现有视图并自动创建新视图。如果该视图是手动创建的(sysarticles (Transact-SQL) 中的 type5),则不删除现有的视图。

如果手动创建自定义筛选存储过程和用于定义已发布项目的视图,则不运行 sp_articleview。而是将它们作为 filtersync_object 参数,与适当的 type 值一起提供给 sp_addarticle (Transact-SQL)

权限

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

示例

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_articlefilter (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 帮助