共用方式為


sp_syspolicy_add_policy_category_subscription (Transact-SQL)

將原則類別目錄訂閱新增到指定的資料庫。

主題連結圖示Transact-SQL 語法慣例

語法

sp_syspolicy_add_policy_category_subscription [ @target_type = ] 'target_type'
        , [ @target_object = ] 'target_object'
        , [ @policy_category = ] 'policy_category'
    [ , [ @policy_category_subscription_id = ] policy_category_subscription_id OUTPUT ]

引數

  • [ @target_type= ] 'target_type'
    這是類別目錄訂閱的目標類型。target_type 是 sysname、為必要項目,而且必須設定為 'DATABASE'。

  • [ @target_object= ] 'target_object'
    這是將要訂閱此類別目錄的資料庫名稱。 target_object 是 sysname,而且為必要項目。

  • [ @policy_category= ] 'policy_category'
    這是要訂閱的原則類別目錄。 policy_category 是 sysname,而且為必要項目。

    若要取得 policy_category 的值,請查詢 msdb.dbo.syspolicy_policy_categories 系統檢視表。

  • [ @policy_category_subscription_id= ] policy_category_subscription_id
    這是類別目錄訂閱的識別碼。policy_category_subscription_id 為 int,而且會當做 OUTPUT 傳回。

傳回碼值

0 (成功) 或 1 (失敗)

備註

您必須在 msdb 系統資料庫的內容中執行 sp_syspolicy_add_policy_category_subscription。

如果您指定不存在的原則類別目錄,就會建立新的原則類別目錄,而且當您執行此預存程序時,所有資料庫都會託管此訂閱。如果您之後針對新的類別目錄清除託管的訂閱,只會針對您指定為 target_object 的資料庫來套用此訂閱。如需有關如何變更託管之訂閱設定的詳細資訊,請參閱<sp_syspolicy_update_policy_category (Transact-SQL)>。

權限

此預存程序會在目前預存程序擁有者的內容中執行。

範例

下列範例會設定 AdventureWorks2008R2 資料庫來訂閱名為 'Table Naming Policies' 的原則類別目錄。

EXEC msdb.dbo.sp_syspolicy_add_policy_category_subscription @target_type = N'DATABASE'
, @target_object = N'AdventureWorks2008R2'
, @policy_category = N'Table Naming Policies';

GO