Assignment 2
Assignment 2
Question:
Relational Schema:
Student(sID, surName, firstName, campus, email, cgpa)
Course(dept, cNum, name, breadth)
Offering(oID, dept, cNum, term, instructor)
Took(sID, oID, grade)
Answer:
Given,
Student(sID, surName, firstName, campus, email, cgpa)
Course(dept, cNum, name, breadth)
Offering(oID, dept, cNum, term, instructor)
Took(sID, oID, grade)
DBMS ASSIGNMENT 2
So we have,
Offering[dept, cNum] Course[dept, cNum]
Took[sID] Student[sID]
Took[oID] Offering[oID]
2. Student number of all students who have taken csc343 and earned an A+ in
it.
Answer:
Good343(sID) := sID dept=csccNum=343grade90(Took ./ Offering)
3. sID of all students who have earned some grade over 80 and some grade
below 50.
Answer:
(sID grade>80Took) (sID grade<50Took)
4. sID of students who have earned a grade of 85 or more, or who have passed a
course taught by Atwood.
Answer:
HaveHighGrade(sID) = sID grade90Took
PassedAtwood(sID) = sID instructor=Atwoodgrade50(Took ./ Offering)
Answer(sID) := HaveHighGrade PassedAtwood
6. Department and course number of courses that have never been offered.
Answer:
(dept,cNumCourse) (dept,cNumOffering)
DBMS ASSIGNMENT 2
9. Department and cNum of all courses that have been taught in every term
when csc448 was taught.
Answer:
448T erms(term) := term(dept=csccNum=448Offering)
CourseT erms(dept, cNum, term) := dept,cNum,termOffering
ShouldHaveBeen(dept, cNum, term) := dept,cNumCourse 448T erms
W ereNotAlways(dept, cNum, term) := ShouldHaveBeen CourseT erms
Answer(dept, cNum) := (dept,cNumCourse) (dept,cNumW ereNotAlways)
10. Name of all students who have taken, at some point, every course Gries has
taught (but not necessarily taken them from Gries)
Answer:
surName,firstName (sID ((instructor=Gries(Offering) ./ Took )) ./ Student ).
11. sID of student(s) with the highest grade in csc343, in term 20099.
Answer:
DBMS ASSIGNMENT 2
T akers(sID, oID, grade) := (dept=csccNum=343term=20099Offering) ./ T
ook
NotT op(sID, oID, grade) := T1.sID,T1.oID,T1.gradeT1.grade<T2.grade[(T1T
akers)(T2T akers)]
Answer(sID) := sID (T akers NotT op)
12. SIDs and surnames of all pairs of students who've taken a course together.
Answer:
P airs(sID1,sID2) := T1.sID,T2.sID T1.sID<T2.sIDT1.oID=T2.oID[(T1T
akers)(T2T akers)]
OneN ame(sID1,sID2, name1) := sID1,sID2,surNamesID1=sID (P airs
Student)
Answer(sID1,sID2, name1, name2) :=
sID1,sID2,name1,surNamesID2=sID (OneN ame Student)