Composite key: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
I have added examples for clarity
Correcting some spelling mistakes (darryl)
Line 3: Line 3:
This is often confused with a '''composite key''' whereby even though this is also a key that consists of 2 or more attributes that uniquely identify an entity occurrence, at least one attribute that makes up the composite key is not a '''simple key''' in its own right.
This is often confused with a '''composite key''' whereby even though this is also a key that consists of 2 or more attributes that uniquely identify an entity occurrence, at least one attribute that makes up the composite key is not a '''simple key''' in its own right.


An example might be a 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 make up the primary key are simple keys because each represents a unique reference when identifing a student in one instance and a module in the other.
An example might be a 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 make up the primary key are simple keys because each represents a unique reference when identifying a student in one instance and a module in the other.


in contrast, using the same example, imagine we identified a student by their firstName + lastName. In our table representing students on modules our primary key would now be firstName + lastName + moduleCode. Because firstName + lastName represent a unique reference to a student, it is not a simple key, it is a combination of attributes used to uniquely identify a student. Therfore the primary key for this entity is a composite key.
In contrast, using the same example, imagine we identified a student by their firstName + lastName. In our table representing students on modules our primary key would now be firstName + lastName + moduleCode. Because firstName + lastName represent a unique reference to a student, it is not a simple key, it is a combination of attributes used to uniquely identify a student. Therefore the primary key for this entity is a composite key.


No restriction is applied to the attributes regarding their (initial) ownership within the [[Data modeling|data model]]. This means that any one, none, or all, of the multiple attributes within the compound key can be [[foreign key]]s. Indeed, a foreign key may itself be a compound key.
No restriction is applied to the attributes regarding their (initial) ownership within the [[Data modeling|data model]]. This means that any one, none, or all, of the multiple attributes within the compound key can be [[foreign key]]s. Indeed, a foreign key may itself be a compound key.

Revision as of 12:46, 17 December 2008

In database design, a compound key is a key that consists of 2 or more attributes that uniquely identify an entity occurrence. Each attribute that makes up the compound key is a simple key in its own right.

This is often confused with a composite key whereby even though this is also a key that consists of 2 or more attributes that uniquely identify an entity occurrence, at least one attribute that makes up the composite key is not a simple key in its own right.

An example might be a 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 make up the primary key are simple keys because each represents a unique reference when identifying a student in one instance and a module in the other.

In contrast, using the same example, imagine we identified a student by their firstName + lastName. In our table representing students on modules our primary key would now be firstName + lastName + moduleCode. Because firstName + lastName represent a unique reference to a student, it is not a simple key, it is a combination of attributes used to uniquely identify a student. Therefore the primary key for this entity is a composite key.

No restriction is applied to the attributes regarding their (initial) ownership within the data model. This means that any one, none, or all, of the multiple attributes within the compound key can be foreign keys. Indeed, a foreign key may itself be a compound key.

Compound keys almost always originate from attributive or associative entities (tables) within the model, but this is not an absolute.

See also

External links