Page 610 - Discrete Mathematics and Its Applications
        P. 610
     9.2 n-ary Relations and Their Applications  589
                                                      TABLE 8 Flights.
                                                       Airline   Flight_number   Gate    Destination   Departure_time
                                                       Nadir         122          34     Detroit           08:10
                                                       Acme          221          22     Denver            08:17
                                                       Acme          122          33     Anchorage         08:22
                                                       Acme          323          34     Honolulu          08:30
                                                       Nadir         199          13     Detroit           08:47
                                                       Acme          222          22     Denver            09:10
                                                       Nadir         322          34     Detroit           09:44
                                                     and 09:44. SQL uses the FROM clause to identify the n-ary relation the query is applied to, the
                                                     WHERE clause to specify the condition of the selection operation, and the SELECT clause to
                                                     specify the projection operation that is to be applied. (Beware: SQL uses SELECT to represent
                                                     a projection, rather than a selection operation. This is an unfortunate example of conflicting
                                                     terminology.)                                                                  ▲
                                                        Example 13 shows how SQL queries can be made involving more than one table.
                                     EXAMPLE 13      The SQL statement
                                                        SELECT Professor, Time
                                                        FROM Teaching_assignments, Class_schedule
                                                        WHERE Department=’Mathematics’
                                                     is used to find the projection P 1,5 of the 5-tuples in the database (shown in Table 7), which
                                                     is the join J 2 of the Teaching_assignments and Class_schedule databases in Tables 5 and 6,
                                                     respectively, which satisfy the condition: Department = Mathematics. The output would consist
                                                     of the single 2-tuple (Rosen, 3:00 p.m.). The SQL FROM clause is used here to find the join of
                                                     two different databases.                                                       ▲
                                                        We have only touched on the basic concepts of relational databases in this section. More
                                                     information can be found in [AhUl95].
                                 Exercises
                                   1. List the triples in the relation {(a,b,c) | a, b, and c are  7. The 3-tuples in a 3-ary relation represent the following
                                     integers with 0 <a <b <c < 5}.                      attributes of a student database: student ID number, name,
                                   2. Which 4-tuples are in the relation {(a,b,c,d) | a, b, c,  phone number.
                                     and d are positive integers with abcd = 6}?         a) Is student ID number likely to be a primary key?
                                   3. List the 5-tuples in the relation in Table 8.      b) Is name likely to be a primary key?
                                   4. Assuming that no new n-tuples are added, find all the
                                                                                         c) Is phone number likely to be a primary key?
                                     primary keys for the relations displayed in
                                                                                       8. The 4-tuples in a 4-ary relation represent these attributes
                                     a) Table 3.           b) Table 5.
                                                                                         of published books: title, ISBN, publication date, number
                                     c) Table 6.           d) Table 8.                   of pages.
                                   5. Assuming that no new n-tuples are added, find a compos-  a) What is a likely primary key for this relation?
                                     ite key with two fields containing the Airline field for the
                                     database in Table 8.                                b) Under what conditions would (title, publication date)
                                                                                            be a composite key?
                                   6. Assuming that no new n-tuples are added, find a compos-
                                     ite key with two fields containing the Professor field for  c) Under what conditions would (title, number of pages)
                                     the database in Table 7.                               be a composite key?





