Long Scenario: Designing Tables for a Recipe App
This long scenario is invented for teaching. It follows Learner D through designing the database for a personal recipe app, with the decision points where a different choice would lead somewhere else. The aim is to show how normalisation decisions feel in practice.
Version 1: one big table
Learner D starts with a single table, mirroring their old spreadsheet:
| id | recipe | ingredients | cook_minutes |
|---|---|---|---|
| 1 | Pancakes | flour, eggs, milk | 20 |
| 2 | Omelette | eggs, cheese | 10 |
It works for listing recipes. Then they want to answer "what can I cook with eggs?".
Decision point 1: how to search ingredients
Option A: search inside the text with WHERE ingredients LIKE '%egg%'.
Option B: give ingredients their own table.
Learner D tries Option A first. It finds "eggs", but it would also match "eggplant", and it misses "Egg" written with a capital letter in a recipe typed later. Searching inside text is fragile.
What if they stayed with Option A? For a tiny personal list, it might be acceptable. But every new question about ingredients would get harder.
They choose Option B.
Version 2: recipes and ingredients
CREATE TABLE recipes (id INTEGER PRIMARY KEY, name TEXT NOT NULL, cook_minutes INTEGER);
CREATE TABLE ingredients (id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE);
But how does a recipe know its ingredients?
Decision point 2: linking recipes and ingredients
Option A: add ingredient_id to recipes. That only allows one ingredient per recipe. Ruled out.
Option B: add recipe_id to ingredients. That only allows each ingredient in one recipe, but eggs appear in both. Ruled out.
Option C: a linking table between them, because this is a many-to-many relationship.
CREATE TABLE recipe_ingredients (
recipe_id INTEGER REFERENCES recipes(id),
ingredient_id INTEGER REFERENCES ingredients(id),
quantity TEXT,
PRIMARY KEY (recipe_id, ingredient_id)
);
The linking table also gives a natural home for the quantity, such as "2" or "200 g".
Version 3: answering questions
"What can I cook with eggs?" becomes:
SELECT recipes.name
FROM recipes
JOIN recipe_ingredients ON recipe_ingredients.recipe_id = recipes.id
JOIN ingredients ON ingredients.id = recipe_ingredients.ingredient_id
WHERE ingredients.name = 'eggs';
Exact, reliable and unaffected by "eggplant".
Decision point 3: units
Learner D now wants to scale recipes. "200 g" stored as text is hard to multiply.
Option A: keep text. Simple, but no maths.
Option B: split into amount (a number) and unit (text, such as g or ml).
They choose Option B for new recipes and leave a note to convert old ones later. A reasonable compromise for a personal project.
Decision point 4: categories
Each recipe can be "breakfast", "dinner" or both. Learner D recognises another many-to-many and adds categories and recipe_categories tables, following the same pattern as ingredients.
The final design
| Table | Holds |
|---|---|
| recipes | One row per recipe |
| ingredients | One row per ingredient name |
| recipe_ingredients | Which ingredient is in which recipe, with amount and unit |
| categories | One row per category name |
| recipe_categories | Which recipe is in which category |
What the scenario teaches
- Text lists inside one column are a warning sign.
- When both sides can have many of the other, use a linking table.
- Linking tables can carry facts about the link, such as quantities.
- Small compromises are fine in personal projects, as long as you note them.
For more on the reasoning behind each step, read Inside Normalisation and the recipe box example schema.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.
Illustrative example: the organisations, people, projects and results described on this page are hypothetical. They do not describe a real client or engagement, and no consulting services are offered here.