Consider the following relational schema:
Students (rollno: integer, name: string, age: integer, cgpa: real)
Courses (courseno: integer, cname: string, credits: integer)
Enrolled (rollno: integer, courseno: integer, grade: string)
Which of the following options is/are correct SQL query/queries to retrieve the names of the students enrolled in course number (i.e., courseno) 1470?
Answer
(A), (C), (D)
Explanation
- (A) For each student, the correlated
EXISTSsubquery is true exactly when anEnrolledrow has that student's roll number and course 1470. Correct. - (B)
SIZEOFis not an SQL operator or aggregate function, so this is not a valid query. - (C) The correlated
COUNT(*)counts the student's enrolments in course 1470, and requiring it to be greater than 0 is the same test as (A). Correct. - (D)
rollnois the only attribute common toStudentsandEnrolled, so the natural join pairs each student with their enrolments and the filter keeps course 1470. Because(rollno, courseno)is the key ofEnrolled, each such student appears once. Correct.
Answer: A, C, D