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?

  1. Astudent_no
  2. Bcourse_no
  3. 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.
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. The primary key of a customer table (cust_id, name) is cust_id, and cust_id in an orders table (order_id, cust_id) is defined as a foreign key referring to cust_id in the customer table. The customer table contains only the rows with cust_id 'C1' and 'C2'. What happens when INSERT INTO orders VALUES ('O9', 'C5') is executed in this state?
  2. SQL statements are divided into the data definition language (DDL), data manipulation language (DML) and data control language (DCL). Which one is classified as DDL?
  3. A product table has five rows of (name, price): (pen, 120), (notebook, 250), (eraser, 80), (file, 300), (ruler, 150). Which shows, in order, the rows returned by SELECT name FROM product WHERE price >= 150 ORDER BY price DESC?
  4. The dept column of an employee table contains, from the top row down, Sales, Dev, Sales, Admin, Dev, Sales (six rows in total). How many rows does SELECT DISTINCT dept FROM employee return?
  5. What is the result of executing DELETE FROM employee in SQL without a WHERE clause?