简体   繁体   中英

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 ?

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 ?

  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;
  3. In many-to-many relationships use the multiple columns key of the ids couple, you do not need another 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.

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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