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 JOIN B

A INTERSECT B

SELECT * FROM A NATURAL JOIN B

SELECT * FROM A INTERSECT B

SELECT * FROM ( A NATURAL JOIN B )

SELECT * FROM ( A INTERSECT B )

SELECT * FROM ( SELECT * FROM A INTERSECT SELECT * FROM B )

SELECT * FROM ( A NATURAL JOIN B ) AS C

SELECT * FROM ( A INTERSECT B ) AS C

TABLE A NATURAL JOIN TABLE B

TABLE A INTERSECT TABLE B

SELECT * FROM A INTERSECT SELECT * FROM B

( SELECT * FROM A ) INTERSECT ( SELECT * FROM B )

( SELECT * FROM A ) AS AA INTERSECT ( SELECT * FROM B ) AS BB

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.