The Modeling of Constraints

The Modeling of Constraints

We have studied so far how to model a slice of the real world using entity sets and relationships. However, there are a number of other important features of the real world that we cannot model with the tools seen so far. This additional information frequently takes the form of constraints on the data that go beyond the structural and type constraints imposed by the definitions of entity sets, attributes, and relationships.

Classification of Constraints

The following is a rough classification of frequently used constraints. We shall not cover all of these constraint types here. Additional material on constraints will be provided in "Constraints on Relations" in the context of relational algebra and in "Constraints  and Triggers" in the context of SQL programming.

1. Keys are attributes or sets of attributes that uniquely identify an entity within its entity set. No two entities may agree in their values for all of the attributes that compose a key. It is allowable, though, for two entities to agree on some, but not all, of the key attributes.

2. Single-value constraints are requirements that the value in a certain context be unique. Keys are a main source of single-value constraints, as they require that each entity in an entity set has unique value(s) for the key attribute(s). However, there are other sources of single-value constraints, for example many-one relationships.

3. Referential integrity constraints are requirements that a value referred to by some object actually exists in the database. Referential integrity is similar to a prohibition against dangling pointers, or other types of dangling references, in conventional programs.

4. Domain constraints need that the value of an attribute must be drawn from a particular set of values or lie within a particular range.

5. General constraints are arbitrary assertions that are needed to hold in the database. For instance, we might wish to require that no more than ten stars be listed for any one movie. We shall see general constraint-expression languages in Sections "Constraints on Relations" and "Schema-Level Constraints and Triggers".

There are various ways these constraints are important. They tell us something about the formation of those features of the real world that we are modeling. For instance, keys allow the user to identify entities without confusion. If we know that attribute name is a key for entity set Studios, then when we refer to a studio entity by its name we know we are referring to a unique entity. Moreover, knowing a unique value exists saves space and time, since storing a single value is easier than storing a set, even when that set has exactly one member. Referential integrity and keys also support certain storage structures that allow faster access to data, as we shall discuss in "Index Structures".



Tags