Overview of Constraints

Previous Next

Constraints allow you to implement business rules in your application. These rules specify which data is allowed in the database and which is not. The aim of constraints is to check as early as possible that newly entered or changed data is valid, and to warn the user or correct the data if it is not.

You can write constraints that reject any data manipulation that violates your business rules. For instance, if a user attempts to set a hire date that is earlier than the date of birth for a particular employee, you can write a constraint to reject this input. This type of constraint is called a restrictive constraint.

If data entered by a user requires manipulation of other data, you can have a constraint do this automatically. For example, if the number of participants in a tour reservation changes, you can write a constraint to re-calculate the reservation price. This type of constraint is called a corrective constraint.

Not all business rules need to be dealt with by writing constraints. For example, allowed domain values or cascading delete actions correspond to business rules, but are best defined at domain and relationship level, not through constraints.

One of the strengths of the Rules Engine is that constraints are written in plain SQL. SQL is used to retrieve or manipulate any data in the database, so it is also the most logical means for defining constraints.

NOTE: The USoft Rules Engine has been constructed in such a manner that SQL statements are parsed and processed as efficiently as possible. However, you MUST comply with your RDBMS vendor's SQL guidelines to provide your application with optimum performance.

Constraint Scope

The scope of each constraint is one of the following:

Domains (domain constraints)

Columns within one record (single-record constraints)

Columns within several records (multi-record constraints)

Transitions

The Rules Engine also supports rules that rely on the transition between an old and a new value. An example of a transitional rule is "An amount cannot increase by more than 10% at a time".

You can use the OLD() function in your SQL statements to refer to the old value, or you can set transition properties for the constraint. If you use the OLD() function or set transition properties (or both), you turn the constraint into a transitional constraint.

Time Constraints

It is also possible to write constraints that must be evaluated at a particular time or on a specific date. These are called time constraints.

See Also

Correct and Incorrect Constraints

Active and Inactive Constraints

Restrictive Constraints

Corrective Constraints

Impact Tree

Deferred Constraints

Including Comments in Constraints