Rules Collection

SQL-DMO

SQL-DMO

Rules Collection

The Rules collection contains Rule objects that reference Microsoft® SQL Server™ data integrity constraints implemented as database Rule objects.

Properties
Count Property
Methods
Add Method Refresh Method
Item Method Remove Method (Collections)
ItemByID Method  

Remarks

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 Rule object 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")
  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 earlier, 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.