Skip to content

Page379

Relational Databases

The most common modern database is the relational database, which contains two-dimensional tables of related (hence the term “relational”) data. A table is also called a relation. Tables have rows and columns: a row is a database record, called a tuple; a column is called an attribute. A single cell (intersection of a row and column) in a database is called a value. Relational databases require a unique value called the primary key in each tuple in a table. Table 9.1 shows a relational database employee table, sorted by the primary key (SSN, or Social Security Number).

Table. 9.1 Relational Database Employee Table.

SSN Name Title
133-73-1337 J.F. Sebastian Designer
343-53-4334 Eldon Tyrell Doctor
425-22-8422 Gaff Detective
737-54-2268 Rick Deckard Detective
990-69-4771 Hannibal Chew Engineer

Table 9.1 attributes are SSN, Name, and Title. Tuples include each row: 133-73-1337, 343-53-4334, etc. “Gaff” is an example of a value (cell). Candidate keys are any attribute (column) in the table with unique values: candidate keys in Table 9.1 include SSN and Name; SSN was selected as the primary key because it is truly unique (two employees could have the same name, but not the same SSN). The primary key may join two tables in a relational database.

Foreign Keys

A foreign key is a key in a related database table that matches a primary key in a parent database table. Note that the foreign key is the local table’s primary key: it is called the foreign key when referring to a parent table. Table 9.2 is the HR database table that lists employees' vacation time (in days) and sick time (also in days); it has a foreign key of SSN. The HR database table may be joined to the parent (employee) database table by connecting the foreign key of the HR table to the primary key of the employee table.

Table. 9.2 HR Database Table.

SSN Vacation Time Sick Time
133-73-1337 15 days 20 days
343-53-4334 60 days 90 days
425-22-8422 10 days 15 days
737-54-2268 3 days 1 day
990-69-4771 15 days 5 days