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 發行者。 publisher 是 sysname,預設值是 NULL。

    [!附註]

    publisher 不應搭配 SQL Server 發行者一起使用。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_articlefilter 用於快照式複寫和異動複寫中。

執行含現有訂閱之發行項的 sp_articlefilter,需要重新初始化這些訂閱。

sp_articlefilter 會建立篩選、在 sysarticles (Transact-SQL) 資料表的 filter 資料行中插入篩選預存程序的識別碼,再將限制子句的文字插入 filter_clause 資料行中。

若要建立含水平篩選的發行項,請執行不含 filter 參數的 sp_addarticle (Transact-SQL)。 請提供包括 filter_clause 在內的所有參數來執行 sp_articlefilter,再提供包括相同的 filter_clause 在內的所有參數來執行 sp_articleview (Transact-SQL)。 如果篩選已經存在,且 sysarticles 中的 type1 (記錄式發行項),就會刪除先前的篩選,再建立新的篩選。

如果未提供 filter_name 和 filter_clause,就會刪除先前的篩選,且篩選識別碼會設為 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

請參閱

參考

sp_addarticle (Transact-SQL)

sp_articleview (Transact-SQL)

sp_changearticle (Transact-SQL)

sp_droparticle (Transact-SQL)

sp_helparticle (Transact-SQL)

複寫預存程序 (Transact-SQL)

概念

定義發行項

定義及修改靜態資料列篩選