Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Reference Index > Referential Data Integrity in R:BASE

Constraints

Scroll Prev Top Next More

Constraints provide automatic, database-wide data integrity and referential integrity. The not null constraint restricts data entry. No matter what method is used to enter data, the constraint verifies that the specified column has a value and the value is unique.

 

The primary key, foreign key, and unique key constraints provide both data integrity and referential integrity. The primary key column is automatically not null and unique. Deletions to a table with a defined primary key are automatically restricted if a referenced foreign key is defined. A value cannot be entered into a table with a foreign key unless that value exists in the referenced primary key table.

 

Constraints are similar to rules in that they indicate valid values or conditions that must be met in a table or column before data can be added, changed, or deleted. For instance, deleting a record that contains a value referred to by a foreign key in another table would break referential integrity.

 

Some constraints automatically define indexes when they are created; where they use the index to quickly check the condition. For example, a primary key is a constraint and an index is created on the primary key column(s). A constraint may use an index, but constraints and indexes are two different things. Constraints and indexes are created and listed separately. Constraints are commonly used to refer to primary and foreign keys.

 

Constraint Benefits Over Rules

Using rules to enforce these same data constraints required several different rules. You would need a rule to prevent duplicates (replaced by the primary key or unique constraint), verify a value rules (foreign key), and require a value rules (not null). In addition, you would need to define delete rules to prevent rows being deleted from the primary key table if there were matching rows in the foreign key table. If you wanted to prevent users from changing a primary key value that exists in the foreign key table, you would need to define an additional verify a value rule. Other constraint benefits over rules include:

 

Easier to define

Cannot be turned off, and are always in place

Faster performance