Creating a rule

A rule defines the acceptable values for a table column or a user-defined datatype. For example, the pubs2 sample database rule, title_idrule, allows a column to contain the value “BU” followed by any four digits. Once you create a rule, you can bind it to table columns and to user-defined datatypes.

Privileges

Only a database owner or a user or group with create rule permission can create a rule.

StepsCreating a rule

  1. In a database hierarchy, select the Rules folder.

  2. Select File | New | Rule (Wizard). The Rule Creation wizard opens.

  3. Enter a name for the rule.

  4. Accept the default creator or choose a creator from the drop-down list.

  5. Enter the rule in the Rule Expression box. Enter the part of the rule that follows the as keyword in the create rule statement.

  6. The expression can be any expression valid in a where clause and can include arithmetic operators and relational operators. The expression takes one argument, prefixed by the @ symbol, and refers to the value that is entered via the update or insert command. The expression cannot reference any column or other database object.

  7. Click Finish.

NoteYou can also create a rule using the Add Role (Template). Select Rules and double-click Add Rule (Template).