Consider a database that has the relation schema CR(StudentName, CourseName).…

2017

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

\(\begin{array}{|c|c|} \hline \textbf{StudentName} & \textbf {CourseName} \\\hline \text {SA} & \text{CA} \\\hline \text{SA} & \text{CB}\\\hline \text{SA} & \text{CC} \\\hline \text{SB} & \text{CB} \\\hline \text{SB}& \text{CC} \\\hline \text{SC} & \text{CA}\\\hline \text{SC}&\text{CB} \\\hline \text{SC} & \text{CC} \\\hline \text {SD} & \text{CA} \\\hline \text{SD} & \text{CB}\\\hline \text{SD} & \text{CC} \\\hline \text{SD} & \text{CD} \\\hline \text{SE}& \text{CD} \\\hline \text{SE} & \text{CA}\\\hline \text{SE}&\text{CB} \\\hline \text{SF}& \text{CA} \\\hline \text{SF} & \text{CB }\\\hline\text{SF} & \text{CC} \\\hline \end{array}\)

The following query is made on the database.

\(T1 \leftarrow \pi _{CourseName}\left ( \sigma _{StudentName=SA}\left ( CR \right ) \right )\)

\(T2 \leftarrow CR\div T1\)

The number of rows in \(T2\) is ______________ .

Attempted by 58 students.

Show answer & explanation

Correct answer: 4

Key insight: relational division returns those StudentName values that are paired with every CourseName in the divisor set.

  • Compute T1 = π_{CourseName}(σ_{StudentName=SA}(CR)) = {CA, CB, CC}.

  • CR ÷ T1 returns the StudentName values that are enrolled in every course in {CA, CB, CC}.

  • Check each student: SA has {CA, CB, CC}; SB lacks CA; SC has {CA, CB, CC}; SD has {CA, CB, CC, CD}; SE lacks CC; SF has {CA, CB, CC}.

  • Therefore the students satisfying the division are SA, SC, SD, SF — a total of 4 rows in T2.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir