Professional Documents
Culture Documents
m n
numofcourses STUDENT ENROLLED COURSE
grade
n
TEACHES
office
m
id
PROFESSOR name
Logical Modeling Using the
Relational Model
STUDENT HOBBY
ENROLLMENT
COURSE
TEACHES
PROFESSOR
Professor_id Course_name Course_year
Id Name Office
Mapping from the (E)ER
Model to the Relational Model
• Mapping of Entity Sets
• Mapping of Categorization
Mapping from the (E)ER
Model to the Relational Model
• Mapping of Entity Sets
• Mapping of Categorization
Mapping of Strong Entity Sets
• Derived attributes
• Do not include them
• Multivalued attributes
• Create a new relation R’ for each multivalued attribute A
• Include a foreign key FK to R in R’
• Primary key of R’ is the combination of A and the PK of R
Mapping Strong Entity Set
Examples
office
PROFESSOR
id
PROFESSOR name Id Name Office
name year
credithours
CID
COURSE
hobby id name
numofcourses STUDENT
STUDENT HOBBY
PROFESSOR
id
PROFESSOR name Id Name Office
RELATED RELATIVE
RELATIVE
Mapping from the (E)ER
Model to the Relational Model
• Mapping of Entity Sets
• Mapping of Categorization
Mapping of 1:1 Relationships
Ri Rj
PKi … PKj … FKi A
Ri Rj
PKi … FKj A PKj …
Ri R Rj
PKi … FKi FKj A PKj …
Ri R Rj
PKi … FKi FKj A PKj …
Mapping of 1:1 Relationship
Example (Option 1)
office
PROFESSOR
id
PROFESSOR name Id Name Office Course_name Course_year
LEADS COURSE
CID
COURSE
Mapping of a 1:1 Relationship
Example (Option 2)
office
PROFESSOR
id
PROFESSOR name Id Name Office
LEADS COURSE
CID
COURSE
Mapping of a 1:1 Relationship
Example (Option 3a)
office PROFESSOR
Id Name Office
id
PROFESSOR name
LEADS
1
Professor_id Course_name Course_year
LEADS
COURSE
name
credithours 1 year
Name Year Credit_hours
CID
COURSE
Mapping of a 1:1 Relationship
Example (Option 3b)
office PROFESSOR
Id Name Office
id
PROFESSOR name
LEADS
1
Professor_id Course_name Course_year
LEADS
COURSE
name
credithours 1 year
Name Year Credit_hours
CID
COURSE
Which approach is better here?
PROFESSOR COURSE
19
Which approach is better here?
PROFESSOR COURSE
20
Which approach is better here?
PROFESSOR COURSE
21
Which approach is better here?
office
PROFESSOR
id
PROFESSOR name Id Name Office Course_name Course_year
LEADS COURSE
CID
Better approach because we know that every
COURSE
professor participates in the relationship so no
null values
Which approach is better here?
office
PROFESSOR
id
PROFESSOR name Id Name Office
LEADS COURSE
CID
Better approach because Id of professor is
COURSE
smaller
Mapping of 1:1 Relationships
Summary
• Try to minimize space consumed by
• choosing the relation with the smaller primary key as
the referenced relation
• choosing the relation of the entity set with total
participation as the referencing relation (no null values)
• choosing the relation of the entity set whose most
entities participate in the relationship as the referencing
relation (fewer null values)
• creating a new relation if most entities from both entity
sets do not participate in the relationship
Mapping of 1:N Relationships
1 N N 1
Ei P Ej Ei P Ej
Ri Rj Ri Rj
PKi … PKj … FKi A PKi … FKj A PKj …
Ri Rj Ri Rj
PKi … PKj … PKi … PKj …
R R
FKi FKj A FKi FKj A
Mapping of 1:N Relationship
Example (Approach 1)
office
PROFESSOR
id
PROFESSOR name Id Name Office
LEADS COURSE
CID
Because COURSE is at the N-side, i.e., each
COURSE
course is related to at most one professor only
Mapping of 1:N Relationship
Example (Approach 2)
office PROFESSOR
Id Name Office
id
PROFESSOR name
LEADS
1
Professor_id Course_name Course_year
LEADS
COURSE
name
credithours m year
Name Year Credit_hours
CID
COURSE
Which approach is better here?
PROFESSOR COURSE
29
Mapping of N:M
Relationships
• For each M:N relationship set P with participating
entity sets Ei and Ej whose corresponding relations
are Ri and Rj, respectively
• Create a new relation R with two foreign keys FKi to Ri
and FKj to Rj and include all attributes of P in R
• Primary key of R is FKi and FKj
Mapping of M:N Relationship
Example
office PROFESSOR
Id Name Office
id
PROFESSOR name
LEADS
n
Professor_id Course_name Course_year
LEADS
COURSE
name
credithours m year
Name Year Credit_hours
CID
COURSE
Mapping of n-ary
Relationships
• For each n-ary relationship set P
• Create a new relation S to represent P
• Include primary keys of relations of participating entity
sets as foreign keys in S
• Include all attributes of P as attributes in S
• Primary key of S is the combination of all foreign keys
in general (unless one or more entity sets participating
in P has a cardinality of 1)
Mapping of n-ary
Relationship Example
firstname lastname
name year
credithours
hobby id name
CID
m n
numofcourses STUDENT TEACHES COURSE
grade
1 office
id
PROFESSOR name
Mapping of N-ary
Relationship Example (2)
STUDENT HOBBY
TEACHES
Student_id Course_name Course_year Professor_id Grade
COURSE
PROFESSOR
Id Name Office
Mapping from the (E)ER
Model to the Relational Model
• Mapping of Entity Sets
• Mapping of Categorization
Mapping of Specializations
and Generalizations
• Given a superclass S and subclasses S1, S2, …, Sn
• Map the superclass S into a relation R
• Map each subclass Si into a relation Ri
• Include a foreign key to R in each Ri
• Primary key of Ri is primary key of R
• Works for all specializations/generalizations (total or
partial, overlapping or disjoint)
Mapping of Specialization
Example
firstname lastname
hobby id name
STUDENT
gpa
thesis
numofcourses
UNDERGRAD POSTGRAD
Mapping of Specialization
Example (2)
STUDENT HOBBY
UNDERGRAD POSTGRAD
Id Gpa Id Thesis
Mapping of Specializations
and Generalizations (2)
• Given a superclass S and subclasses S1, S2, …, Sn
• Map each subclass Si into a relation Ri
• Include all attributes of S in each relation Ri
• Primary key of Ri is the key of S
• Works only for total specializations/generalizations (i.e.,
every entity in the superclass must belong to at least one of
the subclasses)
• Only recommended if
• the specialization is disjoint, otherwise, we repeat the same
entity with its superclass attributes multiple times, and
• there are few specific attributes and relationships for the
superclass
Mapping of Specialization
Example
firstname lastname
hobby id name
STUDENT
gpa
thesis
numofcourses
UNDERGRAD POSTGRAD
Mapping of Specialization
Example (2)
UNDERGRAD UNDERGRAD_HOBBY
POSTGRAD POSTGRAD_HOBBY
hobby id name
STUDENT
gpa
thesis
numofcourses
UNDERGRAD POSTGRAD
Mapping of Specialization
Example (2)
STUDENT HOBBY
id name
PERSON
hobby office
numofcourses
Type=“staff ”
Type=“student”
STUDENT STAFF
Mapping of Generalization
Example (2)
PERSON HOBBY
• Mapping of Categorization
Mapping of Categorization
OWNER
name
id name
address
job
PERSON COMPANY
Mapping of Specialization
Example (2)
OWNER
Account_no Balance
PERSON COMPANY