Vous êtes sur la page 1sur 25

Lecture 05

Entity-Relationship Model
E-R Diagrams

Ch 4.1 (3rd ed)

 

     
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
    



 Note that   could also serve as a


key, but we must select only one 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.

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!
Other Constraints
4. Domain constraints
Example: salary > 1 million
5. Degree constraints
Example: No more than 10 stars listed for any
one movie.

()c
  % 

cm

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.

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.


In E/R Diagrams
     

# #% " 




Note: must be rounded


because each player needs
a team to help with the key.
ƥ Double diamond for supporting many-one relationship.
ƥ Double rectangle for the weak entity set.
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
     

# #% " 



 

 
 

 * # #%   &


#$ 

Design uechniques
1. Faithfulness: reflect the reality
2. Avoid redundancy.
3. Limit the use of weak entity sets.
4. Donƞt use an entity set when an
attribute will do.

!
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

Vous aimerez peut-être aussi