I have three relations:
Course(courseNum, units, time, room)
Student(ID, name, degree)
Takes(ID, courseNum)
I need a relational algebra expression that shows a list of courses that have no graduate student plus associated information (courseNum, units, time, room).
How can I use the relational algebra to find a relation that indicates "this course does not have grad students"?
how can I use the relational algebra to find a relation that indicates this course does not have grad students?
R MINUS S
holds rows that are in R but not in S.
So if R with attributes r1, ... holds tuples that make a true proposition (statement) from some (characteristic) predicate (sentence template) r parameterized by r1, ... and S with attributes r1, ... holds tuples that make a true proposition from some predicate s in terms of r1, ... then R MINUS S
holds tuples that make a true proposition from predicate r
AND NOT
s
.
Similarly JOIN
corresponds to AND
, UNION
to OR
, PROJECT
attributes kept
to EXISTS
attributes dropped
, RESTRICT
condition
to AND
condition
, etc. That is how we know how to build a particular query--we use relation operators that return the tuples we want given that the base/named relations hold (via updates) the tuples satisfying their predicates (per the design).
(To use MINUS
& UNION
we sometimes have to rearrange a predicate expression to get argument expressions with the same attributes. And we have get any NOT
s to appear in AND NOT
. Often this is done by applying De Morgan's laws & distributive laws. Find the names of students who are not enrolled in any course - Students, Faculty, Courses, Offerings, Enrolled)
Relational algebra for banking scenario
Forming a relational algebra query from an English description
Is there any rule of thumb to construct SQL query from a human-readable description?