07-17-2004, 10:13 PM
Hi everyone,
Haven't posted here in a bit, but I'm trying to figure out how to do something in mySQL, and I don't know what the correct approach is.
Basically, I'm looking to make a database for storing recipes. Obviously, the straightforward method is to just copy my blog code and change 'blogtext' to 'recipetext' -- but I'd like to chop it up into a few more fields than that... prep time, notes, instructions, description, picture, etc...
And then there's the ingredients. As I see it, they should be a table within the larger table so that in the future, a query could be done looking for 'all recipes containing tomatoes' or something like that without resorting to a text-search.
Anyhow, even if I'm making this a whole lot more complicated than it needs to be, I'd like to learn how to set up a relationship like this in SQL.
In brief: How can a record in a table contain links to an uncertain number of records in another table? Even better, could I say that bread contains water, flour, oil, salt, and yeast in these quantities, whereas muffins contain the same things in different quantities?
Thanks for any help.
Mike
EDIT: Okay, I'm doing it with three tables: Recipes, Ingredients, and Intersections, where the intersection table contains a record with the IDs of each instance of an ingredient in a recipe... additional benefit: it can contain the quantity! So I've got that part sorted out, but if anyone has any suggestions to put forward, I'd love to hear them.
Haven't posted here in a bit, but I'm trying to figure out how to do something in mySQL, and I don't know what the correct approach is.
Basically, I'm looking to make a database for storing recipes. Obviously, the straightforward method is to just copy my blog code and change 'blogtext' to 'recipetext' -- but I'd like to chop it up into a few more fields than that... prep time, notes, instructions, description, picture, etc...
And then there's the ingredients. As I see it, they should be a table within the larger table so that in the future, a query could be done looking for 'all recipes containing tomatoes' or something like that without resorting to a text-search.
Anyhow, even if I'm making this a whole lot more complicated than it needs to be, I'd like to learn how to set up a relationship like this in SQL.
In brief: How can a record in a table contain links to an uncertain number of records in another table? Even better, could I say that bread contains water, flour, oil, salt, and yeast in these quantities, whereas muffins contain the same things in different quantities?
Thanks for any help.
Mike
EDIT: Okay, I'm doing it with three tables: Recipes, Ingredients, and Intersections, where the intersection table contains a record with the IDs of each instance of an ingredient in a recipe... additional benefit: it can contain the quantity! So I've got that part sorted out, but if anyone has any suggestions to put forward, I'd love to hear them.