DB03
DB03
Relation Schema:
Students(ID, firstName, lastName, GPA, address)
Converting Entity Sets to Relations
Entity Set: Relation Instance:
title year title year length filmType
Star Wars 1997 124 color
Movies Mighty Ducks 1991 104 color
Wayne’s World 1992 95 b&w
length filmType
Relation Schema:
Movies(title, year, length, filmType)
Converting Entity Sets to Relations
Entity Set: Relation Instance:
name address
name address
Fox Hollywood
Studios Disney Hollywood
Paramount Hollywood
Relation Schema:
Studios(name, address)
Converting Relationships to Tables
◼ For each relationship set R, create the corresponding table (relation)
and determine its attributes.
◼ The set of attributes of this table includes:
◼ “Implicitly”: Key attribute(s) of the entity sets involved in the relationship R
◼ “Explicitly”: every attribute used ”explicitly” in R
From Relationships to Tables
Relationship Set:
lastName firstName courseNumber name
Relation Instance:
Relation Schema: ID courseNumber grade
123 Comp248 A-
EnrolledIn (ID, courseNumber, grade)
456 Comp248 B
What is the primary key of this relation? 123 Comp353 A+
From Relationships to Tables
Relationship Set:
credits address
Relation Instance:
Relation Schema: courseNumber DID
Comp248 1
GivenBy(courseNumber, DID)
Comp352 1
What is the primary key of this relation? Math207 9
From Relationships to Tables
Relationship Set:
lastName firstName ID name
address
researchArea address
Relation Instance:
Relation Schema: PID DID
Chair(PID, DID) 234 1
451 2
What is the primary key of this relation? 778 9
Identifying Key of Relationship R
◼ We are already familiar with the concept of key
◼ If R is a binary relationship between entity sets E1 and E2, then the
multiplicity of this relationship determines the key of R
◼ If R is M-N, then the keys of E1 and E2 together are “part of” the key of R
◼ If R is M-1 from E1 to E2, then the key of E1 is part of the key of R
◼ If R is 1-1, then either E1 or E2 (but not both) is part of the key of R
◼ Do the above rules regarding the formation of keys apply to:
◼ Multi-way relationships?
◼ How to determine keys for:
◼ Weak entity sets?
◼ Entity sets and relationship sets in isa hierarchies?
Converting Relationships to Tables
◼ We should rename the attributes in the relations created
when:
◼ An entity set is involved in a relationship more than once
◼ The same attribute name appears in the keys of different entity
sets involved in the relationship (e.g., ID in previous example)
◼ This is to avoid ambiguity in the schema and to be more clear
in meanings
Relationship Sets to Relations
Relationship Set: name address
Studios
Producing Studio
studio of star
title year name address
Movies Contracts Stars
Relation Schema:
Do we need to keep the
Crews (number, name) relation Unit-of?
Unit-of (number, studioName, name)
Studios (name, address)
Weak Entity Sets to Relations
Weak Entity Set:
Relation Schemas:
Sub-Crews (number,crewNumber, name)
Studios (name, address)
Weak Entity Sets to Relations
name address
Weak Entity Set:
Studios
Producing Studio
studio of star
Contracts
isa
isa GPA address
SupervisedBy
major
option
GradStudents UgradStudents
Movies
to Stars
isa
isa length filmType
Voices
weapon
Murder-
Cartoons
Mysteries
Relation Schemas: Movies (title, year, length, film Type)
Cartoons (title, year) Do we really need this?
What about
Cartoon-Murder-Mysteries? Murder-Mysteries (title, year, weapon)
Voices (starName, title, year)
The NULL Values Approach
◼ If we are allowed to use NULL as a value in tuples, we can
handle a hierarchy of entity sets (classes) with a single
relation
◼ This relation has all the attributes belonging to any entity set (class)
of the hierarchy.
◼ An entity/object is represented by a single tuple that has NULL in
each attribute that is not defined for that entity/object.
Converting isa Hierarchy to Relations:
The Null Approach
isa hierarchy: lastName firstName
to Professor ID Students
isa
isa GPA address
SupervisedBy
major
option
GradStudents UgradStudents
Relation Schemas:
SupervisedBy (ID, professorID)
Student (ID, lastName, firstName, GPA, address, option, major)
NULL Approach
◼ The null approach: supports efficient query processing but is
inefficient in space utilization. Why?
◼ Answering queries: the nulls approach allows us to find, in a single
relation R, every tuple/object from any set involved in the hierarchy
◼ Allows us to find all the information about an entity/object in a
single tuple in R
◼ The down side is its space utilization which is too costly for having
repeated and redundant information:
◼ Note: Nulls are not allowed in the relational model theory,
but practically, it is supported by commercial DBMS
A quick test!
◼ Suppose R is a M-1 relationship from entity set
E1={a1, a2} to E2={b1, b2}. Which of the following is
NOT a valid instance of R?
◼ R = {(a1, b1), (a1, b2)}.
◼ R = {(a1, b1)}.
◼ R = {(a2, b1)}.
◼ R={}