如何在数组中存储数据库中的多个值 [英] How do I store multiple values from database in a array

查看:105
本文介绍了如何在数组中存储数据库中的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有3张桌子,其中1张是关系表,有2张外键设置如下:



食谱--- FKRecipesIngredients ---配料



假设ID为1的食谱有3种配料分配给它,那么FK表就像这样:



食谱1 - 成分ID 1

食谱1 - 成分ID 2

食谱1 - 成分ID 3


现在我想删除id为1的配方及其所有成分,这意味着首先我必须看看哪些成分被分配给recipeID 1 ...如何在这种情况下获得这些ID 1,2和3从FKRecipesIngredients表中存储它们并将它们存储在int []数组中,以便我可以使用这些值从Ingredient表中删除它们并最终从Recipe表中删除配方?

解决方案

如果链接并级联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.


这篇关于如何在数组中存储数据库中的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆