Database Basics
An enrollment table (student_no, course_no, grade) records which student took which course and with what grade. One student takes several courses, and one course is taken by several students. If the same student never registers for the same course twice, which is an appropriate primary key for this table?
- Astudent_no
- Bcourse_no
- CThe combination of student_no and course_no
Show answer and explanation
Answer: C. The combination of student_no and course_no
Because one student takes several courses, student_no alone appears in several rows and cannot identify a row uniquely. Likewise, because one course is taken by several students, course_no alone is not unique either. Combining student_no and course_no determines a single row, given that the same student never registers for the same course twice. A primary key made of several columns like this is called a composite key, and in SQL it is specified by listing the columns, as in PRIMARY KEY (student_no, course_no). The student_no and course_no columns of the enrollment table are also foreign keys referring to the primary keys of the student and course tables, and this table represents the many-to-many relationship between students and courses.
- A. One student takes several courses, so student_no alone is duplicated.
- B. One course is taken by several students, so course_no alone is duplicated.
- C. Correct. Combining the two columns gives a composite key that determines a single row.