经过一些研究后,我需要一些建议。这是一个小项目,允许教师在线发布作业,学生可以查看/提交这些作业。
学生可以分配多门类(class),所以我的问题是:设置表格的最佳方式是什么?
示例1:
student courses
John Smith Math, Chemistry, English
Mary White Math, Biology
示例2:
course students
Math John Smith, Mary White
Biology Mary White
Chemistry John Smith
English John Smith
如果这是一个菜鸟问题,我提前道歉,但我想避免从一开始就做错事情,并且我愿意接受任何和所有建议!
感谢您的宝贵时间。
最佳答案
通常不适合在关系数据库的列中放置多个项目。因此创建一个像这样的表:
course student
Math John Smith
Math Mary White
Biology Mary White
Chemistry John Smith
English John Smith
然后,您可以在 JOIN 表达式中使用此表来检索所需的信息。您可能需要额外的表格来描述有关类(class)和学生的基本信息。像这样的东西:
course instructor time
Math Albert Einstein 10:30
和
student id_number phone
John Smith 1234-5678 555-1212
...或您需要保留的有关类(class)和学生的任何信息。
关于mysql - 关于建立数据库表的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9754779/