Databases · Junior · Question 67 of 75

What is a composite primary key?

CREATE TABLE enrollments (
  student_id bigint REFERENCES students (id),
  course_id  bigint REFERENCES courses (id),
  PRIMARY KEY (student_id, course_id)
);

Explanation

Composite keys are typical for junction tables. Each column alone may repeat; only the combination must be unique.

Further reading

Problem with a question

Databases · Junior · question 67

Test yourself

Take the Databases · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz