Attributes-Entities   «Prev  Next»

Lesson 10 Constraints
ObjectiveList Entity and Attribute Constraints

List Entity and Attribute Constraints

Constraints are rules imposed upon certain elements in a database to preserve data integrity[1].
Entity and attribute constraints, of course, are rules imposed upon entities and attributes. Several constraints were mentioned in this module, and are summarized below.

Entity constraints

The following two constraints were identified for entities:
  1. Every entity in a database must have a different name.
  2. Every entity must have an entity identifier ( key attribute).

Attribute constraints

The following two constraints were identified for attributes:
  1. Every attribute must have a specific domain type ( “domain constraint”).
  2. Every attribute must be single-valued.

As the course progresses, other constraints will be identified and explained.
The next lesson concludes the module.

Domains

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:
  1. Yesno: Yes, No
  2. Gender: Male, Female, Unknown
  3. 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:
  1. CODE and
  2. 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.
[1] 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.