Superkey

Print Print
Reading time 4:56

In the relational model of databases, a superkey or super-key of a relation schema is a set of attributes such that each instance relation of the relation schema does not have two distinct tuples with the same values for these attributes.[1][2] It defines a functional dependency constraint from the superkey to all the attributes of the relation schema.

The set of all attributes is a trivial superkey, because in relational algebra duplicate rows are not permitted: rows are a set (no duplicates), not a multiset (duplicates allowed). The superkey is also known as superset key.

If attribute set K is a superkey of relation R, then at all times it is the case that the projection of R over K has the same cardinality as R itself.

A superkey is a set of attributes within a table whose values can be used to uniquely identify a tuple. A candidate key is a minimal set of attributes necessary to identify a tuple; this is also called a minimal superkey. Given an employee schema consisting of the attributes employeeID, name, job, and departmentID, where no value in the employeeID attribute is ever repeated, we could use the employeeID in combination with any or all other attributes of this table to uniquely identify a tuple in the table. Examples of superkeys in this schema would be {employeeID, Name}, {employeeID, Name, job}, and {employeeID, Name, job, departmentID}. The last example is known as trivial superkey, because it uses all attributes of this table to identify the tuple.

In a real database we do not need values for all of those attributes to identify a tuple. We only need, per our example, the set {employeeID}. This is a minimal superkey—that is, a minimal set of attributes that can be used to identify a single tuple. employeeID is a candidate key.

Example

English Monarchs
Monarch Name Monarch Number Royal House
Edward II Plantagenet
Edward III Plantagenet
Richard III Plantagenet
Henry IV Lancaster

First, list out all the sets of attributes:

• {}  
• {Monarch Name}  
• {Monarch Number}  
• {Royal House}
• {Monarch Name, Monarch Number}
• {Monarch Name, Royal House}
• {Monarch Number, Royal House}
• {Monarch Name, Monarch Number, Royal House}

Second, eliminate all the sets which do not meet superkey's requirement. For example, {Monarch Name, Royal House} cannot be a superkey because for the same attribute values (Edward, Plantagenet), there are two distinct tuples:

  • (Edward, II, Plantagenet)
  • (Edward, III, Plantagenet)

Finally, after elimination, the remaining sets of attributes are the only possible superkeys in this example:

  • {Monarch Name, Monarch Number} (Candidate Key)
  • {Monarch Name, Monarch Number, Royal House}

In reality, superkeys cannot be determined simply by examining one set of tuples in a relation. A superkey defines a functional dependency constraint of a relation schema which must hold for all possible instance relations of that relation schema.

If a relation contains 'n' attributes then maximum number of superkeys possible is 2n.

A relation of degree n has 2n superkeys whenever ∅ is a candidate key for that relation. For example:

President
Name Assumed Office
Joe Biden 2021-01-20

where ∅→{Name, Assumed Office} - meaning only one person can be president. There are four superkeys in President:

• {}
• {Name}
• {Assumed Office}
• {Name, Assumed Office}

See also

References

  1. ^ Date, Christopher (2015). "Codd's First Relational Papers: A Critical Analysis" (PDF). warwick.ac.uk. Retrieved 2020-01-04. Note that the extract allows a “relation” to have any number of primary keys, and moreover that such keys are allowed to be “redundant” (better: reducible). In other words, what the paper calls a primary key is what later (and better) became known as a superkey, and what the paper calls a nonredundant (better: irreducible) primary key is what later became known as a candidate key or (better) just a key.
  2. ^ Introduction to Database Management Systems. Tata McGraw-Hill. 2005. p. 77. ISBN 9780070591196. no two tuples in any legal relation

Further reading

  • Silberschatz, Abraham (2011). Database System Concepts (6th ed.). McGraw-Hill. pp. 45–46. ISBN 978-0-07-352332-3.

External links

By: Wikipedia.org
Edited: 2021-06-19 17:55:21
Source: Wikipedia.org