|
-
Aug 16th, 2007, 09:11 AM
#1
Thread Starter
Registered User
Insert with many-to-many relationship
Hi all,
This is my first project (recipe DB for the family) that involves more than 3 little tables in an Access database, so I think you'll see a lot of me here for awhile.
Using MySQL 5.0 and my tables look somewhat like this:
Recipe
RecipeID
CategoryID
SourceID
Instructions
etc..
Ingredient
IngredientID
Ingredient
RecipeIngredient
RecipeID
IngredientID
Measurement
...
Category
CategoryID
Category
Source
SourceID
Source
..and some other tables like this with just the ID and field.
I'll have one form to fill in all fields. I'm basically looking for some beginning logic on how to insert into these tables because frankly I don't know where to start particlarly with the Recipe-Ingredient many-to-many relationship.
Do I first insert into the Category, Source tables if necessary, get those IDs, then insert into the Recipe table, get that ID and then insert into Ingredient, then finally into the RecipeIngredient junction table? Should this be a stored procedure?
I'd appreciate any sort of general bump in the right direction regarding inserting into multiple tables, some of which have a many-to-many relationship. Thanks again!
-
Aug 16th, 2007, 10:09 AM
#2
Hyperactive Member
Re: Insert with many-to-many relationship
What you need to do is wrap your connection in a transaction. You should always insert your parent rows first, followed by your child rows.
Your insert order should be
Source
Category
Ingredient
Recipe
RecipeIngredient
Last edited by The_Duck; Aug 16th, 2007 at 10:10 AM.
Reason: Cateagory?
-
Aug 16th, 2007, 12:43 PM
#3
Thread Starter
Registered User
Re: Insert with many-to-many relationship
Thanks for the reply duck. I'll give her a shot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|