GATE 2017 CS – Question 56
Consider a database that has the relation schema CR(StudentName, CourseName). An instance of the schema CR is as given below.
| StudentName | CourseName |
|---|---|
| SA | CA |
| SA | CB |
| SA | CC |
| SB | CB |
| SB | CC |
| SC | CA |
| SC | CB |
| SC | CC |
| SD | CA |
| SD | CB |
| SD | CC |
| SD | CD |
| SE | CD |
| SE | CA |
| SE | CB |
| SF | CA |
| SF | CB |
| SF | CC |
The following query is made on the database.
$T1 \leftarrow \pi_{CourseName}(\sigma_{StudentName = 'SA'}(CR))$
$T2 \leftarrow CR \div T1$
The number of rows in $T2$ is ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 4
Explanation
$T1$ is the set of courses taken by SA, which is {CA, CB, CC}. The division $CR \div T1$ returns the students who took all three of those courses. SA, SC, SD and SF each took CA, CB and CC. SB did not take CA, and SE did not take CC. So $T2$ has 4 rows.