EXERCISES
12.1 According to the BNF grammar given in the body of the chapter, which of the following are legal as “stand alone” expressions (i.e., expressions not nested inside other expressions) and which not, syntactically speaking? (A and B are table names, and you can assume the tables they denote satisfy the requirements for the operator in question in each case.)
A
NATURAL JOINB
A
INTERSECTB
SELECT * FROMA
NATURAL JOINB
SELECT * FROMA
INTERSECTB
SELECT * FROM (A
NATURAL JOINB
) SELECT * FROM (A
INTERSECTB
) SELECT * FROM ( SELECT * FROMA
INTERSECT SELECT * FROMB
) SELECT * FROM (A
NATURAL JOINB
) ASC
SELECT * FROM (A
INTERSECTB
) ASC
TABLEA
NATURAL JOIN TABLEB
TABLEA
INTERSECT TABLEB
SELECT * FROMA
INTERSECT SELECT * FROMB
( SELECT * FROMA
) INTERSECT ( SELECT * FROMB
) ( SELECT * FROMA
) ASAA
INTERSECT ( SELECT * FROMB
) ASBB
What do you conclude from this exercise? Perhaps I should remind you that, relationally speaking, intersection is a special case of natural join.
12.2 Take another look at the expressions in Exercise 12.1. In which of those expressions would it be syntactically legal to replace A or B or both by “table literals” (i.e., appropriate VALUES invocations)?
12.3 Let X and Y both be of the same character string type and be subject to the same collation; let PAD SPACE apply to that collation (not recommended, of course); and let X and Y have the values ’42’ and ’42 ’, respectively (note the trailing space in the second of these). Then ...
Get SQL and Relational Theory, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.