共用方式為


Rules Collection

未來的 Microsoft SQL Server 版本將移除這項功能。請避免在新的開發工作中使用這項功能,並規劃修改目前使用這項功能的應用程式。

The Rulescollection contains Rule objects that reference Microsoft SQL Server data integrity constraints implemented as database Rule objects.

顯示目前物件的 SQL-DMO 物件模型

Properties

備註

With the Rules collection, you can:

  • Create SQL Server integrity constraints implemented as rules.

  • Remove a rule definition from an instance of SQL Server.

For more information about creating SQL Server rules, see Rule Object.

To remove a SQL Server data integrity constraint implemented as a rule

  1. Get the Ruleobject that references the targeted constraint from the Rules collection using the Item or ItemByID method. When extracting a Rule object using the name of the referenced rule, use the owner name to qualify the rule name, as in:

    Set oRule = oDatabase.Rules("Rule_RowIDs", "dbo")
    
  2. Use the ListBoundColumns and ListBoundDatatypes methods of the Rule object to report affected columns or user-defined data types. If either method returns items, use the UnbindFromColumn or UnbindFromDatatype methods to resolve dependencies.

  3. Use the Remove method of the Rule object to remove the targeted constraint.

When using the Item method, the Rules collection supports member identification using either name or ordinal reference syntax. Additionally, when using the rule name to select an object from the collection, the Item method allows owner name qualification of the targeted SQL Server constraint. For example:

Set oRule = oDatabase.Rules("Rule_RowIDs", "stevenb")

Or:

Set oRule = oDatabase.Rules(2)

The Remove method of the Rules collection supports member targeting using either the rule name or the ordinal position of the object in the collection. The Remove method does not support rule owner name qualification when using the method to drop a constraint. When using the Rules collection to remove a SQL Server database rule, it is suggested that you use either the Item or ItemByID method of the collection to extract the object referencing the correct rule as illustrated earlier, then use the Remove method of the Rule object to remove the constraint.

[!附註]

Creating or removing SQL Server data integrity constraints implemented as a database rule by using the Rules collection requires appropriate privilege. The SQL Server login used for SQLServer object connection must be a member of the fixed role db_ddladmin or a role with greater privilege.