Ch2 Relational Model
Ch2 Relational Model
▪ A unary operation that returns its argument relation, with certain attributes
left out.
▪ Notation:
∏ A1,A2,A3 ….Ak (r)
where A1, A2, …, Ak are attribute names and r is a relation name.
▪ The result is defined as the relation of k columns obtained by erasing the
columns that are not listed
▪ Duplicate rows removed from result, since relations are sets
▪ Result of:
∏course_id (σ semester=“Fall” Λ year=2017 (section)) ∪
∏course_id (σ semester=“Spring” Λ year=2018 (section))
▪ The set-difference operation allows us to find tuples that are in one relation
but are not in another.
▪ Notation: r – s
▪ Set differences must be taken between compatible relations.
• r and s must have the same arity
• attribute domains of r and s must be compatible
▪ Example: to find all courses taught in the Fall 2017 semester, but not in the
Spring 2018 semester
∏course_id (σ semester=“Fall” Λ year=2017 (section)) −
∏course_id (σ semester=“Spring” Λ year=2018 (section))
Step 3
Name Course_ID
Einstein PHY-101
Step 1
Step 2
• Result
• R ∩ S= R-(R-S)
▪ Notation: R ÷ S
▪ Example: To retrieve the student ID of the Student enrolled all courses:
▪ Student: Courses:
S_ID C_ID C_ID
1001 1 1
1002 1 2
1002 2
1003 2
1002
▪ Query 2
σ dept_name=“Physics” (σ salary > 90.000 (instructor))
▪ The two queries are not identical; they are, however, equivalent -- they
give the same result on any database.
Q5. List all the instructors’ ID who taught in Spring 2020 but not advisors.
Q6: Find the names of all instructors in the Physics department together with
the course id of all courses they taught (3 steps). Is there an Equivalent
Queries for the result? Please specify it.