Rules Collection (SQL-DMO)

The Rules collection contains Rule objects referencing Microsoft® SQL Server™ data integrity constraints implemented as database objects called rules.

Remarks

With the Rules collection, you can:

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 Rule object referencing the targeted constraint from the Rules collection by 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")

  1. 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.
  2. 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 above, then use the Remove method of the Rule object to remove the constraint.


Note 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.


Methods
Add Method Refresh Method
Item Method Remove Method (Collections)
ItemByID Method  

Properties

Count Property


(c) 1988-98 Microsoft Corporation. All Rights Reserved.