dpylt7626401 2015-02-19 12:03
浏览 47
已采纳

在数组中创建新表或存储

I'll try to simplify this as much as possible I'm in the process of developing an application which serves a series of resource(X) each from a category(C) to its users(U). Users will select a Category, then be served the resources from that category. They can choose 6-7 categories(out of 15-16), and once they have selected the category they will be able to select individual resources to be served or not within the category; there will be upwards of 10000 resources of which the user can select at most 40-50. I think storing the category choices as an array called preferences should be fine(correct me if I'm wrong) since it will only be a 20 something character string). However, I'm questioning whether I should do the same with resources since it will will be upwards of 200 character string. My alternative is to create an user-resource table, that lists treats each pairing like a transaction. So user(1) might have 30 rows each associating itself with an individual resources.

So each user has:

  • ID
  • Name
  • Preferences(array of 3 letter abbreviations for categories(C) of resources, max of 6-7 so I don't think putting it in a comma delineated string will be an issue)
  • Resources:Should I include another array here?

Each Category(C) has just:

  • Id
  • name

Each Resource (R) has:

  • ID*
  • Name
  • Category
<b>Or create an User-Resource Table here:</b>
<ul>
<li>Id*</li>
<li>Resource Id:</li>
<li>User Id:</li>
</ul>
  • 写回答

1条回答 默认 最新

  • dsaaqdz6223 2015-02-19 12:09
    关注

    If you store your resources in a string you'll have trouble querying them afterwards. There's no problem in storing 200 characters long strings, but inserting or deleting resources may be troublesome, as well as querying (how do you count the number of users that chose a particular resource for instance ?).

    Create a Users-Resources table to store this. 30 rows per user is not a problem, that's what databases are about. Just take care of creating the right foreign keys and indexes.

    In fact, you should also do the same for preferences.

    Read about database normalization (especially the third normal form).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统