Types of Table Relationships

Table relationships come in several forms:

  • One-to-one relationships

  • One-to-many relationships

  • Many-to-many relationships

For example, suppose you have a table called employees that contains each person's Social Security number, name, and the department in which he or she works. Suppose you also have a separate table called departments, containing the list of all available departments, made up of a Department ID and a name. In the employees table, the Department ID field matches an ID found in the departments table. You can see this type of relationship in Figure 14.1. The PK next to the field name indicates the primary key.

Figure 14.1. The employees and departments tables are related through the DeptID key.

In the ...

Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.