這是我們的3張桌子。我們希望在表格中添加一個新配方。用戶可以在屏幕上填寫RecipeName和Method,他們可以從下拉菜單中選擇3種成分。我們正在用Visual Studio與C#一起工作。添加配方到數據庫,如何?
因此,當用戶填寫每個字段時,RecipeName和Method將被添加到Recipes表中。然後,屬於配方的配料必須添加到IngredientRecipe表中。
如何寫這個查詢,因爲我們不知道RecipeId,因爲這個自動增量?
食譜
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
成分
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
你如何訪問你的數據? –
不知道你用什麼來連接你的數據庫(以及你正在使用的DBMS,儘管很多人可能會認爲MS Sql Server),這很難回答! – joshuahealy
此外,這聽起來很有家庭作業....如果它是家庭作業,那麼它應該被標記爲 – joshuahealy