Relationships

A relationship is an association established between common columns in two tables. A relationship can be:

  • One-to-one

  • One-to-many

  • Many-to-many

One-to-one

In a one-to-one relationship, each row in table A can have at most one matching row in table B, and each row in table B can have at most one matching row in table A. Because all the information in both tables simply could be stored in just one table, one-to-one relationships are used for practical, not theoretical, reasons: They’re used to segregate confidential information for security reasons, to speed queries by splitting monolithic tables, or to avoid inserting nulls into tables that contain columns with non-null values in a small subset of rows.

A one-to-one relationship is ...

Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.