Databases Reference
In-Depth Information
participation constraints of the relationship. In an ER diagram, we indicate total par-
ticipation with a double line between the entity box and the relationship diamond.
Entity or Attribute?
From time to time, we encounter cases where we wonder whether an item should be
an attribute or an entity on its own. For example, an email address could be modeled
as an entity in its own right. When in doubt, consider these rules of thumb:
Is the item of direct interest to the database?
Objects of direct interest should be entities, and information that describes them
should be stored in attributes. Our inventory and sales database is really interested
in customers, and not their email addresses, so the email address would be best
modeled as an attribute of the customer entity.
Does the item have components of its own?
If so, we must find a way of representing these components; a separate entity might
be the best solution. In the student grades example at the start of the chapter, we
stored the course name, year, and semester for each course that a student takes. It
would be more compact to treat the course as a separate entity and to create a class
ID number to identify each time a course is offered to students (the “offering”).
Can the object have multiple instances?
If so, we must find a way to store data on each instance. The cleanest way to do
this is to represent the object as a separate entity. In our sales example, we must
ask whether customers are allowed to have more than one email address; if they
are, we should model the email address as a separate entity.
Is the object often nonexistent or unknown?
If so, it is effectively an attribute of only some of the entities, and it would be better
to model it as a separate entity rather than as an attribute that is often empty.
Consider a simple example: to store student grades for different courses, we could
have an attribute for the student's grade in every possible course; this is shown in
Figure 4-5. Because most students will have grades for only a few of these courses,
it's better to represent the grades as a separate entity set, as in Figure 4-6.
Entity or Relationship?
An easy way to decide whether an object should be an entity or a relationship is to map
nouns in the requirements to entities, and to map the verbs to relations. For example,
in the statement, “A degree program is made up of one or more courses,” we can identify
the entities “program” and “course,” and the relationship “is made up of.” Similarly,
in the statement, “A student enrolls in one program,” we can identify the entities
“student” and “program,” and the relationship “enrolls in.” Of course, we can choose
different terms for entities and relationships than those that appear in the relationships,
but it's a good idea not to deviate too far from the naming conventions used in the
 
Search WWH ::




Custom Search