Database Basics
In an E-R diagram, there is a many-to-many relationship between students and courses: one student takes several courses, and one course is taken by several students. Which is an appropriate way to implement this relationship with relational database tables?
- ACreate a new enrollment table holding student_no and course_no as foreign keys
- BAdd one course_no column to the student table
- CAdd one student_no column to the course table
Show answer and explanation
Answer: A. Create a new enrollment table holding student_no and course_no as foreign keys
An E-R diagram depicts the things managed in a database (entities) and the relationships between them, and each relationship has a multiplicity (cardinality) such as one-to-one, one-to-many or many-to-many. A one-to-many relationship can be represented by giving the table on the many side the primary key of the one side as a foreign key (for example, giving the employee table a dept_code column). A many-to-many relationship, however, cannot be represented by adding one column to either table, because that records only one course per student (or one student per course). Instead, an enrollment table (an associative entity) holding student_no and course_no as foreign keys is placed between them, breaking the relationship into two one-to-many relationships: student to enrollment and course to enrollment. The primary key of the enrollment table is usually the combination of student_no and course_no.
- A. Correct. An associative entity table is added, breaking the relationship into two one-to-many relationships.
- B. Only one course_no can be recorded per student, so enrollment in several courses cannot be represented.
- C. Only one student_no can be recorded per course, so enrollment by several students cannot be represented.