Constraints are rules imposed upon certain elements in a database to preserve data integrity
Entity and attribute constraints, of course, are rules imposed upon entities and attributes.
Several constraints were mentioned in this module, and are summarized below.
The following two constraints were identified for attributes:
- Every attribute must have a specific domain type ( “domain constraint”).
- Every attribute must be single-valued.
As the course progresses, other constraints will be identified and explained.
The next lesson concludes the module.
A very common type of attribute constraint is a set of values that shows the possible values an attribute can have. Such a set is called a domain. Very common domains are, for example:
- Yesno: Yes, No
- Gender: Male, Female, Unknown
- Weekday: Sun, Mon, Tue, Wed, Thu, Fri, Sat
In a conceptual data model you can recognize these as entities with (usually) only two attributes:
Code and Description. These domain entities
are referred to frequently but do not have any 'many' relationships of their own
Typically, you would know all the values before the system is built. The number of values is normally low. Often you would deliver such a system with non-empty code tables.
An alternative model for the (sometimes many) code entities is a more generic, two entity approach:
- CODE and
- CODE TYPE
The conceptual data model has the advantage of fewer relationships per entity as well as easy to understand entities.
The two entity approach has obviously fewer entities and therefore will lead to fewer tables.
Domains that have a large number of values, such as all positive integers up to a particular value, are usually not modeled.
You should list and describe such a constraint in a separate document.
 Data integrity:
A term used to describe the quality (in terms of accuracy, consistency, and validity) of data in a database, in the sense that values required to enforce data relationships actually exist.
Problems with data integrity occur when a value in one table that is supposed to relate to a value in another cannot because the second value either has been deleted or was never entered.