Directions (Q96–100): Academic database schema: 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 refers to professor.empid; hod refers to professor.empid; enrollment.rollno refers to student.rollno; courseid in enrollment and teaching refers to course.courseid; teaching.empid refers to professor.empid; precourseid and courseid in prerequisite refer to course.courseid.
Which of the following queries would retrieve the roll number and names of students who have enrolled for all the prerequisite courses of the 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 * 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, written in SQL as a double NOT EXISTS: there must not exist a prerequisite of 324 for which there is no enrollment by this student. Option C has this structure (with typos: a missing FROM and a misplaced AND).
Note on the official key: the official key says option B. Official/PW key is B. 'e.courseid = ALL (subquery)' compares one enrollment row with every prerequisite, which is true only when there is a single prerequisite (or none), so it does not express 'all prerequisites'.
More Database Management Systems questions
- Given query: select s.rollno from students where s.sex = ALL (select f.sex from professor f where f.empid = s.advisor). Consider the follow…
- Which of the following queries would compute, for each department, the total credits of all the courses offered by the department?
- Which of the following queries would retrieve the dept id and name of all the departments that are such that the total of the credits of al…
- Given query: select s.rollno, s.name from student s where EXISTS (select c.courseid from course c Where c.deptno =5 and EXISTS (select e.*…
- Identify the incorrect statement(s).
- Consider the two relations below. The primary keys are underlined. Identify all possible foreign key(s) from the options based only on the…