减少表中存储的属性数量
我在为数据库创建表时遇到问题。我想记录每个农民的很多状态,比如农民在水稻种植中会执行很多程序,从种植到收获大约有26个程序。
因此,每个农民必须根据农业助理确定的日期遵循每个程序的时间表。我的问题是如何记录此程序状态以记录农民是否遵循时间表?现在,我使用 26 个过程作为活动表的属性,因此在活动表中我有属性等等
farmerID, status1 (for activity 1 eg: Cultivation) ,
status2 (for activity 2 eg: fertilization),
status 3
,直到状态 26...那么这是正确的方法吗?我的讲师说这是不正确的,因为有太多属性。你能帮我解决这个问题吗?我不能再想这个了。
I have a problem in creating a table for a database. I want to record many status for each farmer for example farmer will perform many procedures in paddy farming and have about 26 procedures from cultivation until harvesting.
So, each farmer must follow a schedule for each procedure according to dates fixed by Agriculture assistant. My problem is how can I record this procedure status to record whether the farmer is following the schedule or not? For now, I use the 26 procedures as the attributes for the activity table so in the activity table I have attributes
farmerID, status1 (for activity 1 eg: Cultivation) ,
status2 (for activity 2 eg: fertilization),
status 3
and so on until status 26...so is this the correct way? My lecturer says it is incorrect because so many attributes are there. Can you help me out from this problem? I can't think about this any more.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是处理它的好方法,特别是因为如果不添加新字段(并且让您的代码映射这些新字段),它就无法立即扩展。我会做这样的事情:
tbl_farmer
- farmerId
tbl_status
- 状态ID
- 名称(即修炼等)
tbl_activity
- 农民ID
- statusId
每次农民执行状态更新时,您都将条目放入 tbl_activity 中。基本上 tbl_activity 是一个参考表
Not a good way of handling it, especially since it's not immediately scalable without adding new fields (and having your code map those new fields). I'd do something like this:
tbl_farmer
- farmerId
tbl_status
- statusId
- name (i.e. Cultivation, etc.)
tbl_activity
- farmerId
- statusId
And each time a farmer performs a status update, you place the entry inside tbl_activity. Basically tbl_activity is a reference table
另一种方法是为每个活动(过程)提供一个 id,而不是许多列只有三个。
假设您的活动存储在单独的表中。
An alternative approach would be to give each activity (procedure) an id and instead of many columns only have three.
Assuming that your activities are stored in a separate table.