用户档案数据库设计
我必须为大学项目设计一个用户帐户/个人资料表。我的基本想法如下:
- 用户帐户表(电子邮件、用户名、密码和一堆其他字段)
- 用户配置文件表。
在我看来,有两种方法可以对用户配置文件表进行建模:
将所有字段放入表中 [用户配置文件表]
用户帐户 ID (FK) 用户配置文件 ID (PK) 出生日期 性别(列出可能性别的另一个表的 ID) 爱好 varchar(200) SmallBio varchar(200) 兴趣 varchar(200)
...
将公共字段放在表中并设计一个 ProfileFieldName 表,该表将列出 所有我们想要的领域。例如:
<前><代码>[配置文件字段名称表] ProfileFieldID int(PK) 名称 varchar
名称将是“爱好”、“个人简介”、“兴趣”等...最后,我们将有一个将个人资料与个人资料字段相关联的表:
[ProfileFieldTalbe]
ProfileFieldID int (PK)
UserProfileID FK FK
FieldContent varchar
“FieldContent”将存储有关爱好的小文本,个人简介用户、他的兴趣等等。
这种方式是可扩展的,意味着以这种方式添加更多字段对应于INSERT
。
您对这个架构有何看法?
一个缺点是,现在要收集单个用户的所有个人资料信息,我必须进行加入。
第二个缺点是字段“FieldContent”的类型为 varchar
。如果我希望它是另一种类型(int
、float
、date
、列表框的另一个表的 FK 等)怎么办? )?
i have to design a user account/profile tables for a university project. The basic idea i have is the following:
- a table for user account (email, username, pwd, and a bunch of other fields)
- a user profile table.
It seems to me that there are two ways to model a user profile table:
put all the fields in a table
[UserProfileTable]UserAccountID (FK) UserProfileID (PK) DOB Date Gender (the id of another table wich lists the possible gender) Hobby varchar(200) SmallBio varchar(200) Interests varchar(200)
...
Put the common fields in a table and design an ProfileFieldName table that will list
all fields that we want. For example:[ProfileFieldNameTable] ProfileFieldID int (PK) Name varchar
Name will be 'hobby', 'bio', 'interests' etc...Finally, we will have a table that will associate profiles with profile fields:
[ProfileFieldTalbe]
ProfileFieldID int (PK)
UserProfileID FK FK
FieldContent varchar
'FieldContent' will store a small text about hobbies, the bio of the user, his interests and so on.
This way is extensible, meaning that in this way adding more fields corresponds to an INSERT
.
What do you think about this schema?
One drawback is that to gather all profile information of a single user now i have to do a join.
The second drawback is that the field 'FieldContent' is of type varchar
. What if i want it to be of another type (int
, float
, a date
, a FK to another table for listboxs etc...)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议第二个选项会更好,
您提到的缺点并不是实际的缺点,
使用 JOINS 是从 1 个或多个表检索数据的方法之一,
2)“FieldContent”的类型为 varchar:我知道您将仅创建“FieldContent”所有其他字段
在这种情况下,我建议您可以为每个相应字段设置“FieldContent”,以便您可以提供您希望的任何类型的数据类型。
来到第一个选项,
1)如果将所有字段放在一个表中可能会导致很多混乱,并且如果任何需求发生变化,以后扩展的可行性也会降低
2)将会有很多冗余,因为出色地。
I suggest 2nd option would be better,
The drawbacks which you mentioned are not actual drawbacks,
Using JOINS is one of ways to retrieving the data from the 1 or more tables ,
2) 'FieldContent' is of type varchar : I understand that you are going to create only 'FieldContent' for all your other fields
In that case, I suggest that you can have 'FieldContent' for each corresponding fields so that you can give any any kind of Data Type which you wish.
Coming to the first option,
1)If you put all the fields in one table may lead lot of confusion and provides less feasibility to extend later, if any requirements changes
2)There will be lot of redundancy as well.