edited by
515 views
0 votes
0 votes

Suppose I have 2 relations R(stud_no,name,sex,course) and S(stud_no,course).Can someone says what the following operations returns?

$\prod R-S(r)$ and $\prod R-S,S(r)$

Sir ,I am not able to figure what these $\prod R-S(r)$ and $\prod R-S,S(r)$ expressions returns.Can u pls explain with an example?
Please do help...Thanks in advanvce..

edited by

1 Answer

1 votes
1 votes

This is the division operator. When we say (r / s)- first of all, the attribute set of r must be a super set of that of s. Now, (r/s) will select all tuples from r, which doesn't have any missing corresponding tuple in s- i.e., it works like a quotient. 

Example:

R(stud_no,name,sex,course) and S(stud_no,course)

Let $r = \{<10, \text{Rahul}, M, CS>, <10, \text{Rahul}, M, Che>, <11, \text{Ben}, M, CS>\},\\ s = \{<CS>, <Che>\}$

$$∏_{R−S}(r) - \left(∏_{R−S} \left(∏_{R−S}(r) \times (s) \right) -∏_{R−S,S}(r)\right)$$

  • $∏_{R−S}(r)$ - Select all attributes of R but not S from r.
    $\{<10, \text{Rahul},M>, <11, \text{Ben},M>\}$
  • $∏_{R−S,S}(r)$ - Select all attributes of R but not S  union all attributes of S from r, which is same as selecting all attributes from r, but with attributes of S at end so that we can subtract correctly. 
    $\{<10, \text{Rahul}, M, CS>, <10, \text{Rahul}, M, Che>, <11, \text{Ben}, M, CS>\}$
  • $\left(∏_{R−S} \left(∏_{R−S}(r) \times (s) \right) -∏_{R−S,S}(r)\right)$ - Take the cross product of r (after removing attributes of s) and s and subtract all tuples in r. So, this returns the tuples in $r\times s$ for which $r$ doesn't have a tuple. 
    $∏_{R−S}\{<\text{Rahul}, M, 10, CS>, <\text{Rahul}, M, 10, Che>, <\text{Ben}, M, 11, CS>, <\text{Ben}, M, 11, Che>\}\\ - \{<10, \text{Rahul}, M, CS>, <10, \text{Rahul}, M, Che>, <11, \text{Ben}, M, CS>\} $
    $=∏_{R−S} \{ <\text{Ben}, M, 11, Che>\} $
    $ = \{<11, \text{Ben}, M>\}$

So, $∏_{R−S}(r) - \left(∏_{R−S} \left(∏_{R−S}(r) \times (s) \right) -∏_{R−S,S}(r)\right) \\ = \{<10, \text{Rahul}, M>, <11, \text{Ben}, M>\} - \{<11, \text{Ben}, M>\} \\= \{<10, \text{Rahul}, M>\}$

That is using division operator we are selecting the students who have selected ALL the courses. 

Related questions

0 votes
0 votes
1 answer
2
Ashutosh_17 asked Mar 30, 2023
906 views
Let R be a relation of degree 5 then the total number of projections possible on R is ___?