数据库中的首选项表 [英] Preference table in a database

查看:84
本文介绍了数据库中的首选项表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为咖啡店建立一个数据库,我必须添加的一个表是一个偏好表(咖啡饮料成员更喜欢的)。咖啡饮料和偏好之间的关系是什么?会员和喜好之间的关系是什么?



我尝试过的事情:



i我不确定我是否应该创建一个连接表来连接所有这些关系(如果它们有多对多关系,我必须这样做)或者我应该将它们作为外键添加到首选项表中。

解决方案

您将不得不询问将要使用该软件系统的用户,而不是我们。这应该在软件开发生命周期 [ ^ ]基于您的数据库设计。 数据库设计简介 [ ^ ]


首选项应该是与会员和饮料表相关。



假设您有一张可用饮品表(我们称之为饮料):



DrinkId |喝酒

1 | Cappucino

2 |拿铁

3 |摩卡

4 |浓咖啡





和会员表(会员):



MemberId |会员

1 |汤姆

2 |迪克

3 | Harry





这样的偏好表(偏好):



MemberId | DrinkId

1 | 3

3 | 4



会告诉我们Tom喜欢Mocha而Harry喜欢Espresso。



希望你能来能够看到应该应用外键的位置 - 我们需要确保在Preference表中,MemberId存在于Members中,DrinkId存在于drink中,因此我们需要使用外键建立关系完整性。

i have to make a database for a coffee shop and one of the tables i have to add is a preference table(what coffee drink members prefer). Which is the relation between coffee drinks and preferences? which is the relation betweeen members and preferences?

What I have tried:

i am not sure if i should create a join table to connect all of these relations( if they have many to many relation,i must do this) or i should add these as foreign keys to the preference table.

解决方案

You will have to ask the users who are going to use the software system, not us. This should be carried out at requirement phase of the software development life cycle[^] based on which your database is design. Introduction to database design[^]


The Preference should relate to both the Member and the Drink table.

Let's say you have a table of available drinks (we'll call it Drink):

DrinkId | Drink
1 | Cappucino
2 | Latte
3 | Mocha
4 | Espresso
etc.

and a table of members (Member):

MemberId | Member
1 | Tom
2 | Dick
3 | Harry
etc.

A table of preferences (Preference) like this:

MemberId | DrinkId
1 | 3
3 | 4

would tell us that Tom likes Mocha and Harry likes Espresso.

Hopefully, you'll be able to see where the foreign keys should be applied - we need to ensure that on the Preference table, MemberId exists in Members and DrinkId exists in drinks, so that's the relational integrity that we need to establish with our foreign keys.


这篇关于数据库中的首选项表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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