Database Reference
In-Depth Information
Optional versus Mandatory Relationships
Every relationship in a database needs to be defined as either optional or
mandatory. It helps to think of mandatory relationships as “must have” re-
lationships, and optional relationships as “may have” relationships. For ex-
ample, if you have an Employee entity and an Office entity, an employee
“must have” a home office. The relationship between these two entities
defines the home office for an employee. In this case, we have a non-
identifying relationship, and because we can't have a null value for the
foreign key reference to the Office entity in the Employee entity, this re-
lationship is also described as being mandatory. The relationship defines that
every employee has a single home office, and although an employee may
work in other offices, only one office is considered his or her home office.
Now consider a business that assigns vehicles to some employees. That
business practice is reflected in the data model as an Employee entity and
a Vehicle entity, with a relationship between them. You can see that an
employee “may have” a vehicle, thus fitting our definition of an optional
relationship.
Cardinality
In every relationship we've discussed, we've specified only the general type
of relationship—one-to-one, one-to-many, and many-to-many. In each
case, the description of the relationship is a specification of the number of
records in a parent entity in relation to the number of records in a child en-
tity. To more clearly model the actual relation of the data, you can be more
specific when defining these relationships. What you are specifying is the
cardinality of the relationship.
With a one-to-one relationship, the cardinality is implied. You are
clearly stating that for every one record in the parent entity, there might be
one record in the child entity. It would be more specific to say that there
is “zero or one record in the child entity for every one record in the parent
entity.” But if you mean to say that there absolutely must be a record in
each entity, then the relationship's cardinality would be “one record in the
child entity for every one record in the parent entity.” The cardinality of a
one-to-one relationship is notated as [1:1].
In a one-to-many relationship, notated as [1:M], the cardinality im-
plied is “one or more records in the child entity for every one record in the
parent entity.” But if the intent is that there doesn't need to be a record in
the child entity, then the alternative definition is “zero or more records in
Search WWH ::




Custom Search