Directions (Q96–100): Use the following schema of an academic institution's relational database:
student (rollno, name, degree, year, sex, deptno, advisor) department (deptid, name, hod, phone) professor (empid, name, sex, startyear, deptno, phone) course (courseid, cname, credits, deptno) enrollment (rollno, courseid, sem, year, grade) teaching (empid, courseid, sem, year, classroom) prerequisite (precourseid, courseid)
deptno in student, professor and course refers to department.deptid; advisor (student) and hod (department) refer to professor.empid; rollno in enrollment refers to student; courseid in enrollment and teaching refers to course; empid in teaching refers to professor; precourseid and courseid in prerequisite refer to course.
Which of the following queries would retrieve the roll numbers and names of students who have enrolled in ALL the prerequisite courses of course number 324?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: C.
SELECT s.rollno, s.name FROM student s
WHERE NOT EXISTS (SELECT * FROM prerequisite p
WHERE p.courseid = '324' AND NOT EXISTS
(SELECT * FROM enrollment e
WHERE e.courseid = p.precourseid AND e.rollno = s.rollno))
Explanation
'Enrolled in all prerequisites' is relational division, expressed with a double NOT EXISTS: there is no prerequisite of 324 that the student has not enrolled in. A single enrollment row can equal ALL the prerequisites only if there is just one, and the ANY/EXISTS versions find students with at least one. (The printed paper garbles option C's brackets, and some published keys print B, but B is not a correct division query.)More Database Management Systems questions
- Given the query SELECT s.rollno FROM student s WHERE s.sex = ALL (SELECT f.sex FROM professor f WHERE f.empid = s.advisor); which retrieves…
- Which of the following queries computes, for each department, the total credits of all the courses offered by the department?
- Which of the following queries retrieves the deptid and name of all departments whose total credits of offered courses is strictly greater…
- Given the query SELECT s.rollno, s.name FROM student s WHERE EXISTS (SELECT c.courseid FROM course c WHERE c.deptno = 5 AND EXISTS (SELECT…
- Identify the incorrect statement.
- Consider the two relations below (primary keys: EMP.eid and DEPT.did). Identify all possible foreign key(s) based only on the two relations…