Professional Documents
Culture Documents
Entity-Relationship Model: E-R Diagrams
Entity-Relationship Model: E-R Diagrams
Entity-Relationship Model
E-R Diagrams
c
review
Element types in E/R Model
^ uhree principal element types:
1. Entity sets,
2. Attributes,
3. Relationships
Example
Bars sell some
beers.
Drinkers like
some beers
Drinkers frequent
some bars
!
Revisit EX4.1.3
m
End of review
uhe Modeling of Constraints
^ Classification of Constraints
1. Keys
2. Single-value constraints
3. Referential integrity constraints
4. Domain constraints
5. Degree constraints
Keys
^A key is a set of attributes for one entity set
such that no two entities in this set agree on
all the attributes of the key.
It is allowed for two entities to agree on some, but
not all, of the key attributes.
^We must designate a key for every entity set.
^uhere can be more than one possible keys for
an entity set.
Î
Keys in E/R Diagrams
^½nderline the key attribute(s).
^In an Isa hierarchy, only the root entity
set has a key, and it must serve as the
key for all entities in the hierarchy.
*
Example: name is Key for Beers
c
Example: a Multi-attribute Key
cc
Example: a Multi-attribute Key
$ #
"
"#
'
% &
#
c
Single-value constraints
^ uhe value in certain context be
unique.
Keys
^ Null value: the value is unknown.
Key attributes should not be null value.
^ A relationship R that is many-one from
entity set E to entity set F implies a
single-value constraint.
c
Referential integrity constraints
3. Exactly a value referred to by some
object actually exists in the database.
For example: a studio must exist in the
studios entity set to be referenced by the
relationship Own for a movie.
uo enforce the constraint:
ƥ Forbid the deletion of a referenced entity
ƥ Cascade deletion
()c
%
cm
c
Weak Entity Sets
^Occasionally, entities of an entity set
need Ơhelpơ to identify them uniquely.
^Entity set E is said to be weak if in
order to identify entities of E uniquely,
we need to
follow one or more many-one relationships
from E and
include the key of the related entities from
the connected entity sets.
c
Example
^name is almost a key for football players,
but there might be two with the same name.
^number is certainly not a key, since players
on two teams could have the same number.
^But number, together with the team name
related to the player by Plays-on should be
unique.
cÎ
In E/R Diagrams
Weak Entity-Set Rules
^A weak entity set has one or more many-
one relationships to other (supporting)
entity sets.
Not every many-one relationship from a
weak entity set need be supporting.
^uhe key for a weak entity set is its own
underlined attributes and the keys for the
supporting entity sets.
E.g., (player) number and (team) name is a
key for Players in the previous example.
c
In E/R Diagrams
!
Avoiding Redundancy
^edundancy occurs when we say the
same thing in two different ways.
^edundancy wastes space and (more
importantly) encourages inconsistency.
uhe two instances of the same fact may
become inconsistent if we change one and
forget to change the other, related version.
m