EXERCISES
6.1 What if anything is wrong with the following SQL expressions (from a relational perspective or otherwise)?
SELECT * FROM S , SPSELECT SNO , CITY FROM SSELECT SNO , PNO , 2 * QTY FROM SPSELECT S.SNO FROM S , SPSELECT S.SNO , S.CITY FROM S NATURAL JOIN PSELECT CITY FROM S UNION SELECT CITY FROM PSELECT S.* FROM S NATURAL JOIN SPSELECT * FROM S JOIN SP ON S.SNO = SP.SNOSELECT * FROM ( S NATURAL JOIN P ) AS TEMPSELECT * FROM S CROSS JOIN SP CROSS JOIN P
6.2 Closure is important in the relational model for the same kind of reason that numeric closure is important in ordinary arithmetic. In arithmetic, however, there’s one situation where the closure property breaks down, in a sense—namely, division by zero. Is there any analogous situation in the relational algebra?
6.3 Given the usual suppliers-and-parts database, what’s the value of the Tutorial D expression JOIN {S,SP,P}? What’s the corresponding predicate? And how would you express this join in SQL?
6.4 Why do you think the project operator is so called?
6.5 For each of the following Tutorial D expressions on the suppliers-and-parts database, give both (a) an SQL analog and (b) an informal interpretation of the expression (i.e., a corresponding predicate) in natural language. Also show the result of evaluating the expressions, given our usual sample values for relvars S, P, and SP.
( S JOIN ( SP WHERE PNO = ‘P2’ ) ) { CITY }( P { PNO } MINUS ( SP WHERE SNO = ‘S2’ ) { PNO } ) JOIN PS { CITY } MINUS P { CITY }( S { SNO , CITY ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access