Databases & Data Storage

Composite Key

Definition

A composite key is a primary key that consists of two or more columns. Each column on its own may not be unique, but the combination of the columns is guaranteed to be unique.

Why It Matters

Composite keys are used in situations where a single column is not sufficient to uniquely identify a record. They are common in "linking" or "associative" tables that represent a many-to-many relationship.

Contextual Example

In a database for a university, a `Enrollments` table links students and courses. It would have a composite primary key consisting of `StudentID` and `CourseID`. This ensures that a student can only be enrolled in a specific course once.

Common Misunderstandings

  • While functionally valid, composite keys can sometimes be more cumbersome to work with than a simple, single-column "surrogate key" (like an auto-incrementing ID).
  • The columns in the composite key can also be part of foreign keys.

Related Terms

Last Updated: December 17, 2025