设计数据库模式的问题

编程入门 行业动态 更新时间:2024-10-22 21:34:32
本文介绍了设计数据库模式的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试开发一个不同用户可以登录并保存数据的应用程序。 例如user1想要添加他们每天消费的他/她最喜欢的食物。 现在我想将这些数据保存在数据库中。 但问题是我已经有了一个数据库对于食物项目。 用户详细数据库也在那里,user_id将是主键。 但是如何为这个要求设计一个好的模式是我的问题。我想让它以这样的方式设计,即可以立刻保存膳食(食物的收集)。如果只有某人可以指导我进行架构设计,我将能够进一步处理。 非常感谢您花时间阅读我的查询:)

Hi, I'm trying to develop an app where different users can log in and save the data. for example user1 wants to add his/her favorite food items they consume daily. Now I want to save this data in the database. but the problem is I already have a database for the food items. user detail database is also there, user_id will be primary key. but how to design a good schema for this requirement is my question. I want it to design in such a way that meal (collection of food) can be saved at once. If only someone could guide me on the schema designing, I will be able to procedd further. Thanks a lot for taking time to read my query :)

推荐答案

如果你有UserDetail和像这样的FoodItem表: UserDetail表: ------------------ UserId用户名 ------ -------- 1 John 2史蒂夫 FoodItem表: ------------------ ItemId ItemName ------ -------- 1汉堡 2 Burrito 3可乐 现在您可以创建UserFoodItem表格,如 UserId ItemId ------ -------- 1 1 1 3 2 2 2 3 这里UserId和ItemId都是UserFoodItem表中的主键。 If you have UserDetail and FoodItem tables like this: UserDetail Table: ------------------ UserId UserName ------ -------- 1 John 2 Steve FoodItem Table: ------------------ ItemId ItemName ------ -------- 1 Burger 2 Burrito 3 Coke Now you can create UserFoodItem table like UserId ItemId ------ -------- 1 1 1 3 2 2 2 3 Here UserId and ItemId both will be primary key in UserFoodItem table.

更多推荐

设计数据库模式的问题

本文发布于:2023-10-18 13:08:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504313.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!