Designing a database of Recipes

database-design

Task

I need database design to record Recipes.

  • Recipes can contain several Ingredients and several ordered HowToSteps.
  • Each HowToStep can be split into ordered HowToSections.
  • A single recipe can contain a mix of several (ordered) HowToStep and (ordered) HowToSection elements.

My Solution

  • Table HowToSection with FK to the table HowToStep with FK to the table Recipe.
  • Table Ingredient with FK to the table Recipe.

Issue

I have no idea how to handle a business rule which stipulates that

  • "A single recipe can contain a mix of several (ordered) HowToStep and (ordered) HowToSection elements".

Best Answer

You'd have a:

RecipeSteps table containing, recipe_id, stepnumber for order, and a HowToStep ref

And:

RecipeSections table containing, recipe_id, sectionnumber for order, and a HowToSection ref

The stepnumber and sectionnumber need to be non overlapping (per recipe_id for the pulling in the steps/sections in an order.