Enforcing Business Rules
When you have or use business rules for entering data, there are several ways you can enforce those rules in your database:
Create and use validation rules to control data entered in database table fields and records. For more information, see Working with Validation Rules.
Prevent duplicate values in fields by using candidate or primary indexes. For more information, see Preventing Duplicate Values in Fields.
Maintain relationships between tables by establishing referential integrity rules using triggers and stored procedures that are invoked when records in database tables are modified. For more information, see How to: Build Referential Integrity Between Tables.
When developing constraints for your database, consider the level at which you want to enforce a business rule and the action that activates the constraint. Constraints activate in the order that they appear in a table. The first violation of any constraint stops the operation.
The following table summarizes the order in which Visual FoxPro enforces data validation constraints, the level at which they apply, and when those constraints are activated.
Level |
Enforcement mechanism |
Activated when |
---|---|---|
Form |
VALID clause |
Moving the record pointer off the record. |
Table |
Triggers |
Changing values in tables with an INSERT, UPDATE, or DELETE operation. |
Field or column |
NULL validation |
Moving out of a field or column in a browse window or changing the field value with an INSERT or REPLACE operation. |
Field or column |
Field-level validation rules |
Moving out of a field or column in a browse window or changing the field value with an INSERT or REPLACE operation. |
Record |
Record-level validation rules |
Updating a record. |
Record |
Candidate/primary index |
Updating a record. |
Note
When a trigger is called, the Alias is always that of the cursor being updated, regardless of the Alias selected in the code that caused the trigger to fire.