关系型数据库设计(MySQL)
我现在正在为基于“人才”的应用程序设计数据库,例如:
- 模特
- 演员
- 歌手
- 舞者
- 音乐家
我昨天开始了一个类似的问题,并从答复中取得了一些进展,但我认为现在开始一个新问题会更容易。这就是我现在所拥有的:
Table talent:
- id
- name
Table subtalent:
- id
- name
- talent_id (FK)
Table user:
- id
- name
任何在网站上注册的用户都可以为这些人才中的一个或多个创建个人资料。人才可以有子人才,例如演员可以是电视演员或戏剧演员或配音演员。
现在我需要知道以下问题的答案:
1)我应该如何存储用户拥有的天赋和子天赋。我认为还需要两个表(talent_user 和 subtalent_user)?
2)用户可以指定他们拥有的每个TOP LEVEL人才的具体信息。每个人才的字段都会有所不同,所以我认为这将需要另一组表格?这些将如何链接到用户记录,即外键是什么?
I am now designing my database for an application based on "Talents", for example:
- Models
- Actors
- Singers
- Dancers
- Musicians
I started a similar question yesterday and have made some progress from the responses but I thought it would be easier to start a new question now. So this is what I have at the moment:
Table talent:
- id
- name
Table subtalent:
- id
- name
- talent_id (FK)
Table user:
- id
- name
Any user who signs up on the website can create a profile for one or more of these talents. A talent can have sub-talents, for example an actor can be a tv actor or a theatre actor or a voiceover actor.
Now I need to know answers to the following:
1) How should I store what talents and sub-talents a user has. I assume there will need to be two more tables (talent_user and subtalent_user)?
2) The user can specify specific information about each TOP LEVEL talent they have. The fields will vary for each talent so I assume this will require another set of tables? And how would these be linked to the user record, i.e. what would the foreign key be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否需要拥有次等人才的次等人才? IE。在某些情况下,您可能拥有许多不同级别的天赋,其中父天赋具有子天赋,但父天赋是另一个天赋的子天赋。哇,好罗嗦啊! :)
在这种情况下,您将使用自引用表。如下所示,
您可以拥有任意数量的类别、子类别。
然后,您将需要一个连接表,因为一个用户可以拥有许多人才,而一个人才可以属于许多用户。
Would you ever need to have a sub-talent of a sub-talent? Ie. There could be circumstances where you have many different levels of talents, where the parent talent has sub talents, but the parent is a sub talent to another talent. Wow, thats wordy! :)
In this case you would use a self referencing table. Like below
You could then have as many categories, sub categories as you like.
You would then need a joining table as a User can have many talents and a talent can belong to many users.
1)我同意。
2)我认为这个问题的答案取决于几个因素。如果您确切地知道不同人才的不同形式是什么,我会让事情变得简单(如“不要想得太难”)并为您将拥有的每种不同类型的形式创建一个表格。否则,您可能只想为所有表单使用一张表,并将表单数据保存为 XML 等形式。这样您就可以保留原始表单的结构,而无需过于复杂的数据库模式。
1) I would agree.
2) I think the answer to this depends on a few factors. If you know exactly what the different forms would be for different talents, I would keep things simple (as in "don't think too hard") and create a table for each different type of form you'll have. Otherwise, you may want to have just one table for all forms and save the form data as, say, XML. That way you could preserve the structure of the original form without having too complicated a database schema.
废弃次要人才。人才是一个分层人才——(ParentTalent 字段)。允许任意深度。
您需要一个将用户链接到人才表中的条目的 UserTalent 表。
Scrap the Subtalent. Talent is a hierarchical talent - (ParentTalent field). Allows arbitrary depths.
You need a UserTalent table linking a user to entries int he talent table.
2)也许你可以使用 Talent_feature 表。这样,对于每个天赋,您都可以列出它所具有的功能。
然后您将拥有一个 User_talent_feature,例如:
这在向人才添加新功能方面提供了很大的灵活性。
1)要么你可以让每个人才都有一个次要人才,这样关系就永远与次要人才有关。所以你永远不会让一个人只是一个演员,而是一个 tv_actor 或 Broadway_actor 等。那么你只需要 user_subtalent 关系。你总能从中找到顶尖人才。或者您可以使用其他答案提出的层次结构。
2) Maybe you can use a talent_feature table. So that for each talent you can list the features that it has.
Then you will have a User_talent_feature such as:
This gives a lot of flexibility in terms of adding new features to a talent.
1) Either you can make every talent have a subtalent so that the relationship will always be to the subtalent. So you will never have a person being just an Actor but rather a tv_actor, or broadway_actor etc. Then you will need just the user_subtalent relation. You can always find the top level talent from this. OR you can use the hierarchical structure proposed by other answers.