The GATE Grind

GATE 2017 CS – Question 56

Databases · Relational Model: Relational Algebra, Tuple Calculus, SQL · 2 marks · Numerical answer

Consider a database that has the relation schema CR(StudentName, CourseName). An instance of the schema CR is as given below.

StudentNameCourseName
SACA
SACB
SACC
SBCB
SBCC
SCCA
SCCB
SCCC
SDCA
SDCB
SDCC
SDCD
SECD
SECA
SECB
SFCA
SFCB
SFCC

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.