且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在数组中存储数据库中的多个值

更新时间:2023-01-22 11:19:23

如果链接并级联sql中的关系,当你删除主键时它将删除所有关系自动化卡利。

So I have got 3 tables, 1 of them is a relation table with 2 foreign keys set up like so:

Recipes---FKRecipesIngredients---Ingredients

Say that recipe with ID 1 has 3 ingredients assigned to it, then the FK table would look like so:

RecipeID 1 -- IngredientID 1
RecipeID 1 -- IngredientID 2
RecipeID 1 -- IngredientID 3

Now I want to delete recipe with id 1 and all the ingredients with it, meaning first I have to see which ingredients are assigned to recipeID 1... how do I get those ID's in this case 1, 2 and 3 from the FKRecipesIngredients table and store them in a int[] array so that I can use those values to delete those from the Ingredient table and eventually delete the recipe from the Recipe table?

If you link and cascade the relation in sql, when you delete the primary key it will delete all the relations automatically.