Sei sulla pagina 1di 4

DBMS 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)

Convert it into Relational Expressions.


1. Student number of all students who have taken csc343
2.Student number of all students who have taken csc343 and earned an A+ in it
3.sID of all students who have earned some grade over 80 and some grade
below 50.
4. sID of students who have earned a grade of 85 or more, or who have passed a
course taught by
Atwood
5.Terms when csc369 was not offered.
6. Department and course number of courses that have never been offered.
7. sID of students who have a grade of 100 at least twice.
8. sID of students who have a grade of 100 exactly twice.
9. Department and cNum of all courses that have been taught in every term
when csc448 was
taught.
10. Name of all students who have taken, at some point, every course Gries has
taught (but not necessarily taken them from Gries)
11. sID of student(s) with the highest grade in csc343, in term 20099.
12. sIDs and surnames of all pairs of students who've taken a course together

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]

1. Student number of all students who have taken csc343.


Answer:
sID dept=csccNum=343(Took ./ Offering)

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

5. Terms when csc369 was not offered.


Answer:
(termOffering) (termdept=csccNum=369Offering)

6. Department and course number of courses that have never been offered.
Answer:
(dept,cNumCourse) (dept,cNumOffering)

DBMS ASSIGNMENT 2

7. sID of students who have a grade of 100 at least twice.


Answer:
AtLeastTwice(sID) :=
T1.sID T1.oID6=T2.oIDT1.sID=T2.sIDT1.grade=100T2.grade=100[(T1T
akers)(T2T akers)]

8. sID of students who have a grade of 100 exactly twice.


Answer:
AtLeastThrice(sID) :=
T1.sID
T1.oID6=T2.oIDT2.oID6=T3.oIDT1.oID6=T3.oIDT1.sID=T2.sID=T3.sIDT1.g
rade=T2.grade=T3.grade=100
[(T1T akers) (T2T akers) (T3T akers)]
ExactlyTwice(sID) := atLeastTwice AtLeastT hrice

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)

Potrebbero piacerti anche