In database management systems, a Composite Key (also called a compound key) is a primary key that consists of two or more attributes combined together to uniquely identify rows in a table. When a single column cannot guarantee uniqueness on its own, the database designer combines several columns to form a composite key.

A composite key is still a candidate key, but it is made up of multiple attributes instead of just one. This is useful for modeling relationships and situations where uniqueness depends on a combination of fields rather than a single field.

What is a Composite Key?

A Composite Key is:

  • A set of two or more columns used together as the primary key of a table.

  • Minimal, meaning no subset of the columns can be removed while keeping the uniqueness property.

  • Used when no single column alone is sufficient to uniquely identify a row.

For example, in a table that records student enrollments, neither Roll_No alone nor Course_ID alone may be enough to uniquely identify a record, but the combination {Roll_No, Course_ID} can be unique.

Example with a Composite Key

Consider an ENROLLMENT table:

Roll_NoCourse_IDSemesterGrade
101C101Fall2024A
101C102Fall2024B
102C101Fall2024B

In this table:

  • Roll_No alone is not unique (each student can enroll in multiple courses).

  • Course_ID alone is not unique (each course can have multiple students).

  • But the combination {Roll_No, Course_ID} can be unique for each enrollment.

So the designer can define:

sql
PRIMARY KEY (Roll_No, Course_ID);

Here, Roll_No and Course_ID together form a composite primary key. The order of columns in the key matters for indexing and queries.

Key Points about Composite Keys

  • A composite key is still a candidate key, just spread over multiple columns.

  • It is chosen when no single attribute can guarantee uniqueness for all rows.

  • In SQL, composite keys are defined by listing multiple columns within the PRIMARY KEY clause.

  • Composite keys are commonly used in relationship tables (many‑to‑many mappings) and historical or time‑based records.

When to Use a Composite Key?

Composite keys are useful when:

  • Modeling many‑to‑many relationships through a junction table (for example, enrollments, orders‑items).

  • Uniqueness depends on a combination of attributes (for example, date and employee ID, year and branch).

  • Business rules require that a specific combination of fields must be unique.

Composite keys are natural where the real‑world uniqueness comes from a pair or group of attributes rather than a single identifier.

Summary

A Composite Key in DBMS is a primary key made up of two or more columns, used when a single column cannot guarantee uniqueness for all rows. It is a special case of a candidate key and is commonly used in junction tables and situations where uniqueness depends on a combination of attributes. Composite keys help maintain data integrity while accurately reflecting real‑world relationships.