E R Diagram
E R Diagram
E R Diagram
• Design Process
• Modeling
• Constraints
• E-R Diagram
• Weak Entity Sets
• Extended E-R Features
• Design of the Bank Database
• Reduction to Relation Schemas
Design Phases
One to One to
one many
Note: Some elements in A and B may not be mapped
to any
elements in the other set
Mapping Cardinalities
Many to Many to
one many
Note: Some elements in A and B may not be mapped
to any
elements in the other set
Complex Attributes
• Attribute types:
– Simple and composite attributes.
– Single-valued and multivalued attributes
• Example: multivalued attribute: phone_numbers
– Derived attributes
• Can be computed from other attributes
• Example: age, given date_of_birth
• Domain – the set of permitted values for
each attribute
Composite Attributes
Redundant Attributes
• Suppose we have entity sets:
– instructor, with attributes: ID, name, dept_name,
salary
– department, with attributes: dept_name, building,
budget
• We model the fact that each instructor has an associated
department using a relationship set inst_dept
• The attribute dept_name appears in both entity sets. Since
it is the primary key for the entity set department, it
replicates information present in the relationship and is
therefore redundant in the entity set instructor and needs
to be removed.
• BUT: when converting back to tables, in some cases the
attribute gets reintroduced, as we will see later.
Weak Entity Sets
• Consider a section entity, which is uniquely identified by
a course_id, semester, year, and sec_id.
• Clearly, section entities are related to course entities.
Suppose we create a relationship set sec_course
between entity sets section and course.
• Note that the information in sec_course is redundant,
since section already has an attribute course_id, which
identifies the course with which the section is related.
• One option to deal with this redundancy is to get rid of
the relationship sec_course; however, by doing so the
relationship between section and course becomes
implicit in an attribute, which is not desirable.
Weak Entity Sets (Cont.)
• An alternative way to deal with this redundancy is to not store the
attribute course_id in the section entity and to only store the
remaining attributes section_id, year, and semester. However, the
entity set section then does not have enough attributes to identify
a particular section entity uniquely; although each section entity is
distinct, sections for different courses may share the same
section_id, year, and semester.
• To deal with this problem, we treat the relationship sec_course as a
special relationship that provides extra information, in this case,
the course_id, required to identify section entities uniquely.
• The notion of weak entity set formalizes the above intuition. A
weak entity set is one whose existence is dependent on another
entity, called its identifying entity; instead of associating a primary
key with a weak entity, we use the identifying entity, along with
extra attributes called discriminator to uniquely identify a weak
entity. An entity set that is not a weak entity set is termed a strong
entity set.
Weak Entity Sets (Cont.)
• Every weak entity must be associated with an
identifying entity; that is, the weak entity set is
said to be existence dependent on the identifying
entity set. The identifying entity set is said to own
the weak entity set that it identifies. The
relationship associating the weak entity set with
the identifying entity set is called the identifying
relationship.
• Note that the relational schema we eventually
create from the entity set section does have the
attribute course_id, for reasons that will become
clear later, even though we have dropped the
attribute course_id from the entity set section.
E-R Diagrams
Entity Sets
● Entities can be represented graphically as follows:
• Rectangles represent entity sets.
• Attributes listed inside entity rectangle
• Underline indicates primary key attributes
Relationship Sets
● Diamonds represent relationship sets.
Relationship Sets with Attributes
Roles
• Entity sets of a relationship need not be
distinct
– Each occurrence of an entity set plays a “role”
in the relationship
• The labels “course_id” and “prereq_id” are
called roles.
Cardinality Constraints
• We express cardinality constraints by drawing either a
directed line (→), signifying “one,” or an undirected line
(—), signifying “many,” between the relationship set
and the entity set.
• One-to-one relationship between an instructor and a
student :
– A student is associated with at most one instructor via the
relationship advisor
– A student is associated with at most one department via
stud_dept
One-to-Many Relationship
• one-to-many relationship between an
instructor and a student
– an instructor is associated with several
(including 0) students via advisor
– a student is associated with at most one
instructor via advisor,
Many-to-One Relationships
• In a many-to-one relationship between
an instructor and a student,
– an instructor is associated with at most one
student via advisor,
– and a student is associated with several
(including 0) instructors via advisor
Many-to-Many Relationship
• An instructor is associated with several
(possibly 0) students via advisor
• A student is associated with several
(possibly 0) instructors via advisor
Total and Partial Participation
● Total participation (indicated by double line): every entity
in the entity set participates in at least one relationship in
the relationship set