Chapter 6: Database Design Using The E-R Model
Chapter 6: Database Design Using The E-R Model
student
Relationship Sets with Attributes
Roles
▪ Binary relationship
• involve two entity sets (or degree two).
• most relationship sets in a database system are binary.
▪ 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
Non-binary Relationship Sets
▪ 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
component
attributes
street_number street_name apartment_number
Representing Complex Attributes in ER Diagram
Mapping Cardinality Constraints
▪ Total participation (indicated by double line): every entity in the entity set
participates in at least one relationship in the relationship set
▪ Let K R
▪ K is a superkey of R if values for K are sufficient to identify a unique tuple
of each possible relation r(R)
• Example: {ID} and {ID,name} are both superkeys of instructor.
▪ Superkey K is a candidate key if K is minimal
Example: {ID} is a candidate key for Instructor
▪ One of the candidate keys is selected to be the primary key.
• Which one?
▪ Foreign key constraint: Value in one relation must appear in another
• Referencing relation
• Referenced relation
• Example: dept_name in instructor is a foreign key from instructor
referencing department
Primary Key
▪ Primary keys provide a way to specify how entities and relations are
distinguished. We will consider:
• Entity sets
• Relationship sets.
• Weak entity sets
Primary key for Entity Sets
▪ 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
• Sections for different courses may share the same sec 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.
▪ 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.
Weak Entity Sets (Cont.)
▪ An entity set that is not a weak entity set is termed a strong entity set.
▪ 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.
Expressing Weak Entity Sets
▪ A weak entity set becomes a table that includes a column for the primary
key of the identifying strong entity set
section ( course_id, sec_id, sem, year )
▪ Example
Representation of Entity Sets with Composite Attributes
▪ Many-to-one and one-to-many relationship sets that are total on the many-
side can be represented by adding an extra attribute to the “many” side,
containing the primary key of the “one” side
▪ Example: Instead of creating a schema for relationship set inst_dept, add
an attribute dept_name to the schema arising from entity set instructor
▪ Example
Redundancy of Schemas (Cont.)
▪ For one-to-one relationship sets, either side can be chosen to act as the
“many” side
• That is, an extra attribute can be added to either of the tables
corresponding to the two entity sets
▪ If participation is partial on the “many” side, replacing a schema by an
extra attribute in the schema corresponding to the “many” side could
result in null values
▪ If inst_dept were partial, then we would store null values for the
dept_name attribute for those instructors who have no associated
department
Redundancy of Schemas (Cont.)
▪ Method 1:
• Form a schema for the higher-level entity
• Form a schema for each lower-level entity set, include primary key
of higher-level entity set and local attributes
▪ Method 2:
• Form a schema for each entity set with all local and inherited
attributes
▪ Chen, IDE1FX, …
Alternative ER Notations
▪ Functional Requirements
▪ Data Flow, Workflow
▪ Schema Evolution
End of Chapter 6