Internet
Fact-checked

At WiseGEEK, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

What Is a Compound Key?

T.S. Adams
T.S. Adams

In database organizational technology, a "key" is a particular attribute in a table used to uniquely identify a specific entity. A compound key uses two or more attributes to accomplish the same objective; only when found in tandem do these items signify a "match" with the target item. Compound keys are generally used for tables whose information structure is too complex to work by using a single key. Another requirement of compound keys is that none of the individual chosen attributes for a compound key can quality as a simple, single-attribute key on its own.

One the most basic examples of a database table requiring a compound key is an employee or student directory. Imagine that the table contains one list for "First Names" and another list for "Last Names." By themselves, neither the first names nor last names of a particular student or employee would be enough to guarantee a unique identification, as it is possible that two or more people in the database could have matching first or last names. When paired into a compound key — using both the "First Name" and "Last Name" entries to identify a particular student or employee — the probability of each combination first and last name being unique rises substantially. Thus, only a compound key of first and last name is sufficient to uniquely identify any particular student or employee.

Woman doing a handstand with a computer
Woman doing a handstand with a computer

Remember that compound keys should only be used if a single-attribute "simple" key is insufficient. Continuing the previous example, if each student or employee also had a unique identification number, it would render the need for compound keys completely superfluous. If a particular student or employee could be identified by their number alone, there would be no need to bother with either their first or last name; the only attribute that matters is the identification number.

Although each individual attribute in a compound key is non-unique on its own, any attribute may nevertheless be selected as a foreign key. A foreign key links together two or more tables in a database. For example, consider a university database in which there is a separate table for student information and teacher information, and the combination of "First Name" plus "Last Name" is used as a compound key in the student table. The same compound key combination of "First Name" plus "Last Name" can therefore be used to link together the student and teacher tables, providing a gateway between the two.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • Woman doing a handstand with a computer
      Woman doing a handstand with a computer