Many-to-One Cardinality
For example, a student can be enrolled only in one course, but a course can be enrolled by many students.
For Student(SID, Name), SID is the primary key. For Course(CID, C_name ), CID is the primary key.
Table Student
SID | Name |
---|---|
1 | A |
2 | B |
3 | C |
4 | D |
Table Course
CID | C_name |
---|---|
c1 | Z |
c2 | Y |
c3 | X |
Table Enroll
SID | CID |
---|---|
1 | C1 |
2 | C1 |
3 | C3 |
4 | C2 |
Now the question is, what should be the primary key for Enroll? Should it be SID or CID or both combined into one? We can’t have CID as the primary key because a CID can have multiple SIDs. (SID, CID) can distinguish table uniquely, but it is not minimum. So SID is the primary key for the relation enrollment.
For the above ER diagram, we considered three tables in the database
Student |
Enroll |
Course |
But we can combine the Student and the Enroll table renamed as Student_enroll.
Table Student_Enroll
SID | Name | CID |
1 | A | C1 |
2 | B | C1 |
3 | C | C3 |
4 | D | C2 |
Student and enroll tables are merged now. So require a minimum of two DBMS tables for Student_enroll and Course.
Note: In One to Many relationships we can have a minimum of two tables.
Minimization of ER Diagrams
Pre-Requisite: ER Diagram
Entity-Relationship (ER) Diagram is a diagrammatic representation of data in databases, it shows how data is related to one another. In this article, we require previous knowledge of ER diagrams and how to draw ER diagrams.
Minimization of ER Diagram simply means reducing the quantity of the tables in the ER Diagram. When there are so many tables present in the ER DIagram, it decreases the readability and understandability of the ER Diagram, and it also becomes difficult for the admin also to understand these. Minimizing the ER Diagram helps in better understanding. We reduce tables depending on the cardinality.