Lecture 13-15 (E.R)
Lecture 13-15 (E.R)
Relationships between more than two entity sets are rare. Most relationships are
binary. (More on this later.)
Example: students work on research projects under the guidance of an instructor.
relationship proj_guide is a ternary relationship between instructor, student, and
project.
Recursive Relationship
Relationship type where same entity type participates more than once in different
roles.
Mapping Cardinality Constraints
Express the number of entities to which another entity can be associated via a
relationship set.
Most useful in describing binary relationship sets.
For a binary relationship set the mapping cardinality must be one of the following
types:
One to one
One to many
Many to one
Many to many
Mapping Cardinalities
Note: Some elements in A and B may not be mapped to any elements in the other
set
Mapping Cardinalities
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
An entity set that does not have sufficient attributes to form a primary key is termed a
weak entity set. An entity set that has a primary key is termed a strong entity set.
For a weak entity set to be meaningful, it must be associated with another entity set,
called the identifying or owner entity set. The weak entity set is said to be existence
dependent on the identifying entity set. The relationship associating the weak entity
set with the identifying entity set is called the identifying relationship.
ER 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
Notation to Express Entity with
Complex 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.
Entities associated through two distinct
relationships with role names
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
Notation for Expressing More Complex
Constraints
A line may have an associated minimum and maximum cardinality, shown in the
form l..h, where l is the minimum and h the maximum cardinality.
Structural Constraints
Multiplicity is made up of two types of restrictions on relationships: cardinality and
participation.
Cardinality
Describes maximum number of possible relationship occurrences for an entity
participating in a given relationship type.
Participation
Determines whether all or only some entity occurrences participate in a
relationship.
Multiplicity as cardinality and
participation constraints
Multiplicity of Staff Manages Branch (1:1) relationship
Multiplicity of Staff Oversees PropertyForRent (1:*)
relationship
Multiplicity of Newspaper Advertises PropertyForRent (*:*)
relationship
Important cardinalities
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