These are our 3 tables. We want to a new recipe into the tables. The user gets a screen where they can fill in the RecipeName, the Method and they can select 3 ingredients from dropdown menu's. We are working with asp.net in visual studio with C#.
So when the user fills in every field the RecipeName and the Method will be added to the Recipes table. Then the ingredients which belong to the recipe have to be added to the IngredientRecipe table.
How to write this query, because we don't know the RecipeId since this autoincrements?
Recipes
RecipeId RecipeName Method
1 Bacon and Brocilli Bake the bacon and cook the brocolli
2 Rice with chicken Cook the rice and bake the chicken
4 Potato and Carrot Cook the potatoes and the carrots
6 Rice Chicken and Carrot Cook everything
Ingredients
IngredientId IngredientName IngredientCategorie
2 Bacon 3
3 Brocolli 2
4 Potato 1
5 Chicken 3
6 Carrot 2
7 Rice 1
IngredientRecipe
RecipeUniqueID RecipeId IngredientId
1 1 2
2 1 3
3 2 5
4 2 7
5 4 4
6 4 6
7 1 4
8 2 6
9 4 2
10 6 7
11 6 6
12 5 5