mysql 设计表中的主从关系
我需要创建 2 个表名册和记录,其中每个名册有许多记录。 花名册基于班级,每个班级每天最多有 1 个花名册。 一个记录可以有很多学生。
我想知道这种主从关系设计是否有效? 我的朋友建议一切都可以在记录表中完成,因为我们想显示特定日期班级中所有学生的花名册。因此,在主从方法中,需要查询2张表来完成任务,相反,如果只有一张记录表,则只需要1次查询即可完成任务。< br> 请指教。
I need to create 2 tables rosters and records, whereby each roster has many records.
A roster is based on class and there is maximum 1 roster for each class per day.
A record can have many students.
I wonder that this master-detail relationship design is effective?
My friend suggests that everything could be done in record table, since we want to display a roster of all the students in a class in a specific day. So in the master-detail approach, it takes query on 2 tables to accomplish the task, in contrast, it take only 1 query if there is only one record table.
Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要跟踪主键值之外的
ROSTER
属性,则数据库规范化规则要求您拆分ROSTER
表。当然,您始终可以选择非规范化,但必须睁大眼睛做出决定。如果除了键之外您没有
ROSTER
列,那么您的朋友是对的。否则,您应该提醒您的朋友,仅仅因为某件事可以做,并不意味着它应该做。If you have attributes of
ROSTER
that you need to track over and above a primary key value, then database normalization rules require you to split out theROSTER
table. Of course, you can always choose to denormalize, but that decision must be made with your eyes wide open.If you don't have columns for
ROSTER
other than a key, then your friend is right. Otherwise you should remind your friend that just because something could be done, doesn't mean it should be done.