Jump to content

Composite key

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 217.38.12.83 (talk) at 10:01, 27 April 2021 (→‎Example). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In database design, a composite key is a candidate key that consists of two or more attributes (table columns) that together uniquely identify an entity occurrence (table row). A compound key is a composite key for which each attribute that makes up the key is a simple (foreign) key in its own right.

Example

An example is an entity that represents the modules each student is attending at University. The entity has a studentID and a moduleCode as its primary key. Each of the attributes that makes up the primary key is a simple key because each represents a unique reference when identifying a student in one instance and a module in the other, so this key is a compound key.

In contrast, using the same example, imagine we identified a student by their firstName + lastName. In a table representing students our primary key would now be firstName + lastName. Because students can have the same firstNames or the same lastNames these attributes are not simple keys. The primary key firstName + lastName for students is a composite key.

See also