douju2599 2013-11-08 07:49
浏览 33
已采纳

如何在坚持规范化的同时将数组存储在数据库中?

I'm creating a website where people can share and upload things, but I want to add a like/recommend button. I want to check that if the user has recommended something or not, so they can't spam click it. I had an idea of how to do it: I had a column called 'recby' for each post and I would store a list of users who had recommended that post separated by commas. Then I learned about normalisation.

How would I do this whilst sticking to normalisation?

  • 写回答

1条回答 默认 最新

  • doulan6150 2013-11-08 07:54
    关注

    You add a table storing the likes for you:

    PostID | UserID
    ---------------
    5      | 6
    5      | 15
    6      | 8
    

    Something like this. Now you have one entry for each like while keeping everything normalized.

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

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题