Java Reference
In-Depth Information
AuthorISBN
Table
The
AuthorISBN
table (described in Fig. 24.7) consists of two columns that maintain
ISBNs for each book and their corresponding authors' ID numbers. This table associates
authors with their books. The
AuthorID
column is a
foreign key
—a column in this table
that matches the primary-key column in another table (that is,
AuthorID
in the
Authors
table). The
ISBN
column is also a foreign key—it matches the primary-key column (that is,
ISBN
) in the
Titles
table. A database might consist of many tables. A goal when designing
a database is to
minimize
the amount of
duplicated
data among the database's tables. For-
eign keys, which are specified when a database table is created in the database, link the data
in
multiple
tables. Together the
AuthorID
and
ISBN
columns in this table form a
composite
primary key
. Every row in this table
uniquely
matches
one
author to
one
book's ISBN.
Figure 24.8 contains the data from the
AuthorISBN
table of the
books
database.
Column
Description
The author's ID number, a foreign key to the
Authors
table.
AuthorID
The ISBN for a book, a foreign key to the
Titles
table.
ISBN
Fig. 24.7
|
AuthorISBN
table from the
books
database.
AuthorID
ISBN
AuthorID
ISBN
1 0132151006 2 0133379337
2 0132151006 1 0136151574
3 0132151006 2 0136151574
1 0133807800 4 0136151574
2 0133807800 1 0133378713
1 0132575655 2 0133378713
2 0132575655 1 0133764036
1 013299044X 2 0133764036
2 013299044X 3 0133764036
1 0132990601 1 0133570924
2 0132990601 2 0133570924
3 0132990601 3 0133570924
1 0133406954 1 0132121360
2 0133406954 2 0132121360
3 0133406954 3 0132121360
1 0133379337 5 0132121360
Fig. 24.8
|
Sample data from the
AuthorISBN
table of
books
.
Every foreign-key value must appear as another table's primary-key value so the
DBMS can ensure that the foreign key value is valid—this is known as the
Rule of Refer-
ential Integrity
. For example, the DBMS ensures that the
AuthorID
value for a particular