doudu8291 2016-07-31 11:41
浏览 10
已采纳

mysql数据库规范化

I'm new to mysql! have absolutely basic knowledge like creating tables only. I'm in the process of creating a website with online examinations and results. My fields include

t_id, t_name(subject),ru_id, ru_name, ru_skl, hs_user, hsu_skl

Legend: t is test. ru is registered users. skl is school. hs is high scored. hsu is high scored user.

I don't know how to arrange the fields in tables and to establish a relationship such that the following conditions are met:
(1) each test can have multiple users registering, for the same test_id.
(2) highest scored user should be obtained and entered into table, for the respective test_id.
(3) highest scored user's school should also be entered into table, for the respective test_id.
(4) conditions 2 n 3 should be retrievable so as to process using php for monthly toppers list, etc.

Kindly require ur help! :)

  • 写回答

1条回答 默认 最新

  • dter8514 2016-07-31 11:57
    关注

    Table: UserToTest Columns:

    test_id | user_id | score
    

    That is actually all you need. Just insert user_id and test_id to establish the relationship. Add the score as additional information.

    All the other data you want to have, max score by user and max score by school are values you can easily compute when querying. So there is no real need to write it in a table, it would only make the datahandling more complicated as you would have to add triggers, constraints or more logic in your application to keep those values up to date.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题