简体   繁体   English

数据库表规范化

[英]Database Table Normalization

Table 1

id  Student
1   Ali
2   Akram
3   Aamir
4   Adeel
5   Aun

Table 2

id  Course
1   English
2   Urdu
3   Maths
4   Physics
5   Chemistry


Table 3

id  stu_id   course_id
1   1          1
2   1          2
3   2          1
4   2          5
5   5          1

Q1: Are these tables normalized ? 问题1:这些表格是否已标准化?

Q2: Help me to remove duplicates from table 3, suppose if table 2 have 1000 courses, and student id 1 and 2 are enrolled in all courses, table 3 will be very large because of 2000 entries , is there any way to reduce these ? 问题2:请帮助我从表3中删除重复项,假设表2中有1000门课程,并且所有课程中都注册了学生ID 1和2,表3由于有2000个条目而将很大,有什么办法可以减少这些?

  1. It is normalized with a many-to-many relation; 通过多对多关系对其进行归一化;
  2. Yes max cardinality of a many-to-many relation like that is max students x max courses, nothing terrible; 是的,像这样的多对多关系的最大基数是最大学生数x最大课程数,没有什么可怕的;
  3. In many-to-many relationships use the multiple columns key of the ids couple, you do not need another id; 在多对多关系中,使用id对的多列键,则不需要另一个id;
  4. If by duplicates you mean the fact you have many equal fields in the columns, that are not duplicates at all. 如果用重复来表示您在列中有许多相等的字段,那么这些字段根本不是重复的。 They mean that a student has many courses and viceversa. 他们意味着一个学生有很多课程,反之亦然。 What has to be unique is the couple stu_id-course_id. 唯一的是夫妇stu_id-course_id。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM