EXERCISES

3.1 Define as precisely as you can the terms attribute, body, cardinality, degree, heading, relation, relation type, and tuple.

3.2 State as precisely as you can what it means for (a) two tuples to be equal; (b) two relations to be equal.

3.3 Write Tutorial D tuple selector invocations for a typical tuple from (a) the parts relvar, (b) the shipments relvar. Also show SQL’s counterparts, if any, to those selector invocations.

3.4 Write a typical Tutorial D relation selector invocation. Also show SQL’s counterpart, if any, to that selector invocation.

3.5 (This is essentially a repeat of Exercise 1.8 from Chapter 1, but you should be able to give a more comprehensive answer now.) There are many differences between a relation and a table. List as many as you can.

3.6 The attributes of a tuple can be of any type whatsoever (well, almost; can you think of any exceptions?). Give an example of (a) a tuple with a tuple valued attribute, (b) a tuple with a relation valued attribute (RVA).

3.7 Give an example of a relation with (a) one RVA, (b) two RVAs. Also give two more relations that represent the same information as those relations but don’t involve RVAs. Also give an example of a relation with an RVA such that there’s no relation that represents precisely the same information but has no RVA.

3.8 Explain the relations TABLE_DUM and TABLE_DEE in your own words. Why exactly doesn’t SQL support them?

3.9 As we saw in the body of the chapter, TABLE_DEE means TRUE and TABLE_DUM means FALSE. Do these facts mean we could dispense with the usual BOOLEAN data type? Also, DEE and DUM are relations, not relvars. Do you think it would ever make sense to define a relvar of degree zero?

3.10 What’s the logical difference if any—as opposed to the obvious syntactic difference—between the following two SQL expressions?

     VALUES   ( 1 , 2 ), ( 2 , 1 ), ( 1 , 1 ), ( 1 , 2 )
     VALUES ( ( 1 , 2 ), ( 2 , 1 ), ( 1 , 1 ), ( 1 , 2 ) )

3.11 What exactly does the following SQL expression mean?

     SELECT SNO
     FROM   S
     WHERE  ( NOT ( ( STATUS , SNO ) <= ( 20 , 'S4' ) ) ) IS NOT FALSE

3.12 Explain in your own words what it means to say that relations are n-dimensional.

3.13 List as many situations as you can think of in which SQL regards left to right column ordering as significant.

3.14 Give an SQL analog for the Tutorial D expression IS_NOT_EMPTY(r).

3.15 I said in the body of the chapter that a relation selector invocation in Tutorial D consists of the keyword RELATION, followed by a commalist of tuple expressions enclosed in braces (and those tuple expressions must all be of the same tuple type)—and I implied, though I didn’t say as much explicitly, that the type of the relation denoted by the overall expression was RELATION {H}, where TUPLE {H} was the common type of all of the specified tuple expressions. But what if the set of specified tuple expressions is empty?—in other words, what if the relation being selected is empty? How can its type be determined?

Following on from the foregoing, how can we specify an empty table in SQL?

3.16 A tuple is a set (a set of components); so do you think it might make sense to define versions of the usual set operators (union, intersection, etc.) that apply to tuples?

3.17 State in your own words, as carefully as you can, the discipline described in the body of the chapter regarding SQL column names.

3.18 The column naming discipline referred to in the previous exercise relies on the use of AS clauses. But such clauses can appear in SQL in several different contexts; moreover, the syntax sometimes takes the form “X AS <something>“ and sometimes “<something> AS X” (if you see what I mean); and the keyword is sometimes optional and sometimes mandatory.[49] List all of the contexts in which AS can appear, showing which are of the form “X AS ...” and which “... AS X”, and in which cases the keyword is optional.



[49] For this reason, in fact, I always show the keyword explicitly, even when it’s not required. It can be hard to remember when keywords are optional in SQL and when they’re mandatory. And in any case it would surely seem strange, in the case of AS in particular, to talk about something being an “AS clause” or “AS specification” if there isn’t any AS.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.117.35