Repaso
Español

One customer can have many orders. Where does the link column go?

Options

  1. An order_id column in the customers table
  2. A customer_id column in orders, the 'many' side (Correct option)
  3. A separate database that links both tables
  4. Both tables store all ids as a list

Answer

A customer_id column in orders (the 'many' side)

Why

In a one-to-many relationship, the 'many' side (orders) stores a foreign key pointing to the 'one' side (customers).

Each order row has exactly one customer_id, while a customer row would need an unlimited list of order IDs, which tables do not store well.

Many-to-many (students ↔ courses) needs a third 'join table' with both IDs.

Remember

One-to-many: put the foreign key on the 'many' side.

Key terms

Practice this question in Repaso