Why Data Lives in Many Tables
Keys and relationships.
Look at the orders table. Each order has a customer ID, a number like one, or two. But not the customer's name. Why not? Why didn't the database just store the name right there in the order?

- Orders store a customer ID
- Not the customer's name
- Why?
A look at orders
Here are the first three orders. Run it. Orders one thousand and one, and one thousand and two, both belong to customer one. Order one thousand and three belongs to customer two. To know who these people are, we need to look in a different table.
SELECT *
FROM orders
LIMIT 3;โโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโโโ โ order_id โ customer_id โ order_date โ status โ โโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโค โ 1001 โ 1 โ 2025-03-06 โ delivered โ โ 1002 โ 1 โ 2024-11-24 โ delivered โ โ 1003 โ 2 โ 2024-06-22 โ delivered โ โโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโ
Why split the data?
Imagine storing the name, email, and city inside every order. A loyal customer with fifty orders would have their address saved fifty times. If they moved house, you'd have to change fifty rows, and if you missed one, your data would disagree with itself. So instead, each customer is stored once, in the customers table, and orders just point to them, using the ID.
Keys
The column that identifies each row is called the primary key. Customer ID is the primary key of customers. No two customers share it. A column that points to another table's primary key is called a foreign key. Customer ID in orders is a foreign key. Keys are the glue between tables.
| key | value |
|---|---|
| Primary key | identifies each row |
| customers.customer_id | primary key |
| Foreign key | points to another table |
| orders.customer_id | foreign key |
Summary
Data is split into tables, so each fact is stored only once, and keys link them together. Next, how to put them back together in a query.
Key takeaways- Each fact stored once
- Primary key: identifies a row
- Foreign key: points to one