基本用户输入的查找表?

发布于 2024-09-27 07:22:45 字数 168 浏览 2 评论 0原文

出生月份、日期和年份、用户年龄、性别等数据。这些数据应该以文本形式存储还是基于 ID 形式存储在数据库中?基于 ID 意味着它们将具有查找值。用法例如:用户注册将记录年龄,用户个人资料将有寻找伴侣的年龄等,因此年龄和其他数据可以在多个地方使用。在后端会有分析,这促使我使用查找表来处理像性别这样只有 2-3 个值的小事情。

Data like Birth month, day and year, user's age, Gender/Sex, etc. Should these be stored as text or ID based in database? ID based means they will have lookup values. Usage is for example: User signup will record age, user profiles will have a seeking partner age, etc so age and other data can be used in multiple places. In backend there will be analytic which is pushing me to use lookup tables for even small things like Gender which have only 2-3 values.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的那抹悲凉 2024-10-04 07:22:45

您将需要引用可用的数据类型或数据库。对于 mysql: http://dev.mysql.com/doc/ refman/5.0/en/data-types.html

不要使用您提到的任何字段作为主键。创建“id”列或使用用户的用户名。

以下是字段的数据库:

  • birthDate = date
  • Age = tinyint(从技术上讲,您不需要这个,因为您始终可以根据他们的birthDate和当前日期确定它。这取决于您在做什么)
  • gender = enum

You will want to reference the datatypes or database has avilable. For mysql: http://dev.mysql.com/doc/refman/5.0/en/data-types.html

Do not use any of the fields you mentioned as the primary key. Either create an 'id' column or use the user's username.

Here are database for the fields:

  • birthDate = date
  • age = tinyint (Technically you don't need this since you can always determine it based on their birthDate and current date. It depends what you are doing)
  • gender = enum
无法回应 2024-10-04 07:22:45

我不会为你提到的字段查找表而烦恼。出生月、日、年都可以封装在一个日期字段中(带有日期类型,而不是文本),然后根据需要使用数据库函数进行拆分。年龄只是一个数字,这就是您的 id 字段的全部内容,因此除非您想实际限制年龄范围,否则进行查找没有多大意义,在这种情况下,您可以使用检查约束而不是查找,如果您需要限制在实际范围内(例如年龄 >= 1 和年龄 <= 20)。性别/性别是我可能考虑查找的唯一一个,但由于可能的值很少,因此检查约束就足够了。

哦,我不知道您使用的是什么分析,但是任何有价值的分析软件都可以自行生成字段域(表字段中的唯一值列表),特别是对于您提到的字段。如果您正在构建自己的分析(不确定,根据您对其他发帖者解决方案的评论),您可以轻松地进行查询来完成您正在谈论的事情。

I wouldn't bother with lookup tables for the fields you mentioned. Birth month, day, year could all be encapsulated in a single date field (w/ date type, not text), and then split out with database functions if you need. Age is just a number, which is all your id field will be, so not much point in making a lookup for that unless you want to actually limit the age range, in which case you could use a check constraint instead of a lookup if you needed to limit to an actual range (age >= 1 and age <= 20 for instance). Gender/sex is the only one I might consider a lookup on, but since there are so few possible values, a check constraint should suffice.

Oh, and I don't know what analytic you're using, but any analysis software worth its salt can produce field domains (lists of unique values in a table's fields) on its own, especially for the fields you mentioned. If you're building your own analytic (not sure, based on your comment to another poster's solution), you can easily make queries to do what you're talking about.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文