Consider the following relational schema.
- Students(rollno: integer, sname: string)
- Courses(courseno: integer, cname: string)
- Registration(rollno: integer, courseno: integer, percent: real)
Which of the following queries are equivalent to this query in English?
“Find the distinct names of all students who score more than in the course numbered 107”
-
SELECT DISTINCT S.sname FROM Students as S, Registration as R WHERE R.rollno=S.rollno AND R.courseno=107 AND R.percent >90
View worked solution
Answer: A
To find the correct option, let us analyze each of the given query representations to see if they correctly express the English query: “Find the distinct names of all students who score more than in the course numbered 107”.
I. SQL Query
SELECT DISTINCT S.sname FROM Students as S, Registration as R WHERE R.rollno=S.rollno AND R.courseno=107 AND R.percent > 90
- Join Condition:
R.rollno = S.rollnocorrectly joins theStudentsandRegistrationtables. - Filtering:
R.courseno = 107 AND R.percent > 90filters for the specified course and score. - Projection:
SELECT DISTINCT S.snameensures only distinct student names are returned.
Thus, Query I is correct.
II. Relational Algebra (RA) Query
- Natural Join:
Registration ⋈ Studentsjoins the two relations on their common attribute, which isrollno. - Selection: filters the joined tuples.
- Projection: projects the student names. In relational algebra, the projection operator inherently eliminates duplicate values.
Thus, Query II is correct.
III. Tuple Relational Calculus (TRC) Query
- This query defines a target tuple containing a single attribute
sname(since ). - It asserts the existence of a student tuple and a registration tuple such that their
rollnovalues match, the course number is , and the score is greater than .
Thus, Query III is correct.
IV. Domain Relational Calculus (DRC) Query
- The domain variables are mapped as follows:
- For
Students(rollno, sname): where isrollnoand issname. - For
Registration(rollno, courseno, percent): where isrollno, the course number is bound to constant , and ispercent.
- For
- The condition filters for scores greater than .
- The output is the domain variable representing the student's name.
Thus, Query IV is correct.
Conclusion
Since all four queries (I, II, III, and IV) are equivalent and correct, the correct option is A.
Free practice · Your answers on this page are not saved.
