in Databases edited by
12,797 views
52 votes
52 votes

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 ______________ .

in Databases edited by
by
12.8k views

1 comment

How many Students have enrolled in all the same courses that Student “SA” has enrolled in :

SA enrolled in  CA, CB, CC courses → $T1 = \{ CA, CB, CC \}$

from Course table we apply division operator since we want “all” students who enrolled in $T1$  $ = \frac{CR}{T1}$  

SA → {CA , CB, CC}  $\supseteq T1$              → (1)

SB → {CB, CC} $\nsupseteq T1$

SC → {CA , CB, CC}  $\supseteq T1$              → (2)

SD → {CA , CB, CC, CD} $\supseteq T1$        → (3)

SE → {CA , CB, CD} $\nsupseteq T1$

SF → {CA , CB, CC} $\supseteq T1$                → (4)

So Out of 6 students are enrolled in ALL courses enrolled by Student SA

1
1

5 Answers

72 votes
72 votes
Best answer

ANS) 4

T1 WILL GIVE :- $\begin{array}{|c|c|c|} \hline \text {1. CA} \\\hline  \text {2. CB} \\\hline  \text {3. CC} \\\hline \end{array}$

T2 = CR $\div$  T1 $=$ All the tuples in CR which are matched with every tuple in T1 : $\begin{array}{|c|c|c|} \hline \text {1. SA} \\\hline  \text {2. SC} \\\hline  \text {3. SD} \\\hline \text{4. SF} \\\hline \end{array}$

//SB IS NOT MATCHED WITH CASE IS NOT MATCHED WITH CC 

edited by

2 Comments

One row of SD is also not matched. What about that?
0
0

The values taken in T2 will be the tuples in CR which matches with every tuple in T1

SA matches with 

SA CA
SA CB
SA CC

SB matches with only CB CC but not CA so it has not been taken

SB CB
SB CC

Similarly, SC matches with all the tuples in T1 CA, CB and CC so it has been taken 

SD matches with all the tuples in T1 CA,CB and CC so it has been taken. Since, CD is not in table T1 so it doesn't affect.

SE doesn't match with every tuple in T1, it matches only with CA, CB(in T1) and CD but CD is not present in T1.

SF matches with all the tuples present in T1 so it has also been taken.

 

4
4
22 votes
22 votes

plz make me correct if i m wrong.....

0 votes
0 votes
Be executing query on T1 → CA,CB,CC

T2 <--CR/T1  ,So ans will be those Student name having T1(i.e CA,CB,CC(all 3)) ,So studend name -->SA,SC ,SD,SF  contains T1 &lsquo;s 3 course name ,so answer will be 4 .
0 votes
0 votes
Be executing query on T1 we get -->CA,CB,CC

T2 = CR/T1  ,So ans will be those Student name having T1( i.e CA,CB,CC(all 3)) ,So student name -->SA,SC ,SD,SF  contains T1&rsquo;s  all 3 course name ,so answer will be 4 .
Answer:

Related questions