开发者

Reducing number of attributes stored in table

开发者 https://www.devze.com 2023-02-19 17:21 出处:网络
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 cul

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 t开发者_如何学JAVAhis 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.


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


An alternative approach would be to give each activity (procedure) an id and instead of many columns only have three.

farmer_id
activity_id
status

Assuming that your activities are stored in a separate table.


Reducing number of attributes stored in table

0

精彩评论

暂无评论...
验证码 换一张
取 消