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?

  1. ACreate a new enrollment table holding student_no and course_no as foreign keys
  2. BAdd one course_no column to the student table
  3. 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.
Practice this topic Back to topic

Related calculators

Books on Database Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Database Basics questions

  1. In an account table, a transaction is started, and an UPDATE that subtracts 300 from account A's balance and an UPDATE that adds 300 to account B's balance are executed. Then ROLLBACK is executed instead of COMMIT. What happens to the account table?
  2. Among the ACID properties a transaction should have, which is the property that a transfer debiting account A and crediting account B is either carried out completely or not at all, even if a failure occurs partway through?
  3. The stock count of a product in a stock table is 10. Transaction T1 reads the stock count and writes back the value minus 3, and T2 reads the stock count and writes back the value minus 5. If they run without locks in the order T1 reads, T2 reads, T1 writes, T2 writes, what is the final stock count?
  4. Among the problems that occur when transactions run concurrently, which correctly describes a dirty read?
  5. Transaction T1 ran SELECT COUNT(*) FROM orders WHERE amount >= 1000 and got 8. Immediately afterwards, T2 inserted an order row with an amount of 2000 and committed. When T1 ran the same SELECT statement again, it got 9. What is this phenomenon?