liveBook · Manning

One-to-many relationship

As explained in Learn SQL in a Month of Lunches

A one-to-many relationship is a relationship in which one record on one side can correspond to multiple records on the other side.

A one-to-many relationship connects one record on one side with multiple records on the other. For example, each order belongs to one customer, while one customer may place several orders. section 8.1.2

Store customers separately and replace repeated customer names in orders with CustomerID. If an order contains several items, store those items separately as well; each order can then relate to multiple item records. section 8.1.2

Customer orders and order items

A customer table can identify each customer once, an orders table can assign each order to one CustomerID, and an order-items table can list the products within each order. This avoids repeating customer information and helps provide unique keys for orders. section 8.1.2

Figure 8.6 Our hypothetical orders table with a CustomerID column to reference names in the customer table

Inspect the hypothetical orders table to see how repeated customer names become a single CustomerID reference. section 8.1.2

How Learn SQL in a Month of Lunches covers it

How deep it goes
Defines the relationship and demonstrates two table-design applications, while deferring worked examples of other relationship types.
Examples
Uses customer-orders and order-items tables to show repeated relationships and separated data.
What you can do after
Build it from scratch by separating repeated customer and item data into related tables.
How it connects
Connects relational databases with primary keys, referenced key values, and related tables.

Also explained in

Compare how 12 books explain one-to-many relationship →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.