Week4 Workshop
Week4 Workshop
2 Conceptual Design
Entity-Relationship Model
3 Logical Design
From Entity-Relationship Model to Relation Schemas
4 Physical Design
Phase 2: Conceptual Design
What is a model?
A model is
a simplification of reality
often a graphical depiction of data
associated with a modeling language
Attribute as oval;
Entity as rectangles;
Relationship as diamonds.
(Exercise 1) Consider the following data requirements for a university
student database that is used to keep track of students’ transcripts.
The university keeps track of each student’s name, student number, social
security number, address, phone, and birthdate. Both social security
number and student number have unique values for each student.
Each student has exactly one major, and may have a minor (if any) with
departments.
Each department has name, department code, office number, office phone,
and college. Both name and code have unique values for each department.
Each course has a course name, description, course number, number of
semester hours, level, and offering department. The value of course number
is unique for each course.
Each section of a course has an instructor, semester, year, and section
number and the section number distinguishes different sections of the same
course that are taught during the same semester/year; its values are 1, 2, 3,
..., up to the number of sections taught during each semester.
A grade record refers to each student and a particular section, consisting of
a final mark and a letter grade from (F, D, C, B, A).
Entities, Relationships and Attributes
Each student has name, student number, social security number, address,
phone and birthdate. Both social security number and student number have
unique values for each student.
Question: What are the entities, relationships and attributes?
Entities: STUDENT
Relationships:
Attributes: name, student number, social security number, address,
phone and birthdate for STUDENT
Entities, Relationships and Attributes
Each student has exactly one major, and may have a minor (if any) with
departments
Question: What are the entities, relationships and attributes?
Entities: STUDENT, DEPARTMENT
Relationships: has major with between STUDENT and
DEPARTMENT , has minor with between STUDENT and DEPARTMENT
Attributes: name for has major with , name for has minor with
Constraints on Relationships
Each student has exactly one major, and may have a minor (if any) with
departments.
Question: What are the constraints on relationship “has major with”?
Cardinality ratios: Every student has at most one major and a department
may offer many majors (to different students)
Participation constraints: Every student must have one major (total) and
each department must (typically) offer one major (total).
Constraints on Relationships
Each student has exactly one major, and may have a minor (if any) with
departments.
Question: What are the constraints on relationship “has minor with”?
Cardinality ratios: Every student has at most one minor and a department
may offer many minor (to different students)
Participation constraints: Every student may or may not have one minor
(partial) and each department must (typically) offer one minor (total).
Entities, Relationships and Attributes
A conceptual data model is translated onto a logical data model, which can
be further refined (e.g., normalisation) to meet the data requirements. For
example,
From: An ER model
To: Relations with their primary and foreign keys, which facilitates SQL
to deal with retrieving, updating and deletion.
Note: The logical design is based on the relational data model in this
course.
ER-to-Relations Algorithm
7-step algorithm to convert the basic ER model into relations, and more
steps for the EER model.
If both sides are partial, we may create a (new) relation schema which
cross-references the PKs of the relation schemas of the two entity types.
M ANAGES(SSN, Dname, Start date) with
PK: {SSN} or {Dname}
FKs: [SSN]⊆E MPLOYEE[SSN] and [Dname]⊆D EPARTMENT[Name]
Can we still merge them into a single relation using previous approaches?
We cannot; otherwise what would be the primary key for the merged relation
schema?
Step 4: Binary 1:N Relationship Types
For each 1:N relationship type R, extend the relation schema of the
N-side entity type by the attributes of R and the PK of the 1-side entity
type, where
PK: still the PK of the N-side entity type
FK: references the PK of the 1-side entity type
G RADE REPORT (ssn, section num, course num, letter grade, final mark)
PK: {ssn, section num, course num}
FK: [ssn] ⊆ S TUDENT[ssn]
FK: [section num, course num] ⊆ S ECTION[section num, course num].
Step 6: Multi-valued Attributes
For each multi-valued attribute A, create a relation schema with an
attribute corresponding to A plus the PK of the entity/relationship type that
has A as an attribute, where
PK: the combination of A and the PK of the entity/relationship type
that has A
FK: references the PK of the entity/relationship type that has A
The algorithm to first convert the basic ER model into relations, and then
convert superclass/subclass from the EER model into relations.