Keys in the Relational Model
Superkey
Read aloud is unavailable in this browser.
The Foundation of Data Uniqueness
In the physical world, we identify individual entities through unique characteristics—people by fingerprints or government IDs, books by ISBN numbers, vehicles by VIN codes, and buildings by addresses. This fundamental need for unique identification extends directly into the digital realm of relational databases.
Within a relational database, every tuple (row) in a relation (table) must be uniquely distinguishable from every other tuple. Without this guarantee, we lose the ability to reference specific data, update precise records, or maintain meaningful relationships between tables. The superkey is the foundational concept that makes this identification possible.
Before we can understand primary keys, foreign keys, or referential integrity, we must first master the superkey—the most general and inclusive form of a key in relational theory.
By the end of this page, you will understand the formal definition of a superkey, recognize why superkeys form the foundation of the relational key hierarchy, identify all possible superkeys for any given relation schema, and appreciate the mathematical properties that govern superkey behavior.
The Uniqueness Problem
Before defining superkeys formally, let's understand the problem they solve. Consider a simple Employee relation:
| EmployeeID | FirstName | LastName | Department | HireDate | |
|---|---|---|---|---|---|
| E001 | John | Smith | Engineering | john.smith@corp.com | 2023-01-15 |
| E002 | Jane | Doe | Marketing | jane.doe@corp.com | 2022-08-20 |
| E003 | John | Smith | Sales | john.smith2@corp.com | 2024-02-10 |
Now ask yourself: How do we refer to a specific row?
- By
FirstName? No—there are two 'John' entries - By
LastName? No—there are two 'Smith' entries - By
FirstName+LastName? Still no—there are two 'John Smith' entries - By
Email? Yes—each email is unique - By
EmployeeID? Yes—each ID is unique - By
EmployeeID+Email? Yes—but this is more than necessary
This simple exercise reveals a critical insight: uniqueness is an attribute (or combination of attributes) property, and some combinations are more efficient than others.
A relational database fundamentally requires the ability to uniquely identify any tuple within a relation. Operations like UPDATE, DELETE, and JOIN all depend on this capability. Without unique identification, we cannot distinguish between 'update John Smith in Engineering' and 'update John Smith in Sales'.
The Mathematical Formulation:
Let R be a relation schema with attributes {A₁, A₂, ..., Aₙ}. A subset K ⊆ {A₁, A₂, ..., Aₙ} has the uniqueness property if no two distinct tuples in any valid instance of R can have the same values for all attributes in K.
Formally, for any valid instance r of R and any two tuples t₁, t₂ ∈ r:
If
t₁[K] = t₂[K], thent₁ = t₂
This states that if two tuples agree on all attributes in K, they must be the same tuple. Equivalently, different tuples must differ on at least one attribute in K.
This uniqueness property is the defining characteristic of a superkey.
Formal Definition of Superkey
With the uniqueness problem understood, we can now define the superkey with full mathematical precision:
A superkey of a relation R is a set of one or more attributes that, taken collectively, allows us to uniquely identify any tuple in any valid instance of R. Formally, a set of attributes K is a superkey of R if K → R (K functionally determines all attributes of R).
Key aspects of this definition:
- Set of attributes: A superkey can consist of one attribute or many attributes
- Collective uniqueness: The attributes work together to provide uniqueness
- Any valid instance: The uniqueness must hold for all possible database states, not just the current one
- Functional determination: The superkey functionally determines every attribute in the relation
The functional dependency perspective:
If K is a superkey of R(A₁, A₂, ..., Aₙ), then:
K → A₁K → A₂- ...
K → Aₙ
Or more concisely: K → R (K determines all of R).
This connection between superkeys and functional dependencies is profound. It means that understanding superkeys requires understanding functional dependencies—a topic we'll explore in detail later. For now, the intuition is: if you know the superkey values, you know everything about that tuple.
| Component | Description | Example |
|---|---|---|
| Attribute set K | One or more columns that form the superkey | {EmployeeID} or {Email} |
| Uniqueness constraint | No two distinct tuples share the same K values | Two rows cannot both have EmployeeID = 'E001' |
| Universal validity | Constraint holds across all valid database states | Not just current data, but all possible future data |
| Functional determination | K → R (knowing K means knowing everything) | Given EmployeeID, we can determine all other attributes |
Properties of Superkeys
Superkeys exhibit several important mathematical properties that govern their behavior. Understanding these properties is essential for correctly identifying superkeys and appreciating the key hierarchy.
- •Superset Property: If K is a superkey, then any superset of K is also a superkey. Adding more attributes cannot reduce uniqueness—if {EmployeeID} uniquely identifies tuples, then {EmployeeID, FirstName} also uniquely identifies them.
- •Trivial Superkey: The set of all attributes in a relation is always a superkey. Since a relation cannot contain duplicate tuples (by definition), the complete attribute set must be unique.
- •Non-Emptiness: Every relation has at least one superkey—the trivial superkey consisting of all attributes. This guarantees that the key hierarchy is never empty.
- •Functional Dependency Foundation: K is a superkey of R if and only if K → R holds. This connects superkeys to the broader theory of functional dependencies.
- •Closure Property: If K is a superkey, then K⁺ (the closure of K) equals the entire attribute set of R. The closure contains all attributes that K functionally determines.
The superset property means superkeys can be arbitrarily large. In a relation with n attributes, if {A} is a superkey, then so are {A,B}, {A,B,C}, and all subsets containing A—potentially 2^(n-1) superkeys just from this one minimal key! This is why we need the concept of 'candidate keys' (minimal superkeys) to avoid this explosion.
Proof: Superset Property
Let K be a superkey of R, and let K' ⊇ K (K' is a superset of K). We prove K' is also a superkey:
- Since K is a superkey, for any two tuples t₁, t₂: if t₁[K] = t₂[K], then t₁ = t₂
- If t₁[K'] = t₂[K'], then certainly t₁[K] = t₂[K] (since K ⊆ K')
- By step 1, t₁ = t₂
- Therefore K' satisfies the uniqueness property
- Therefore K' is a superkey ∎
Proof: Trivial Superkey Always Exists
Let R have attribute set {A₁, A₂, ..., Aₙ}. By the definition of a relation:
- A relation is a set of tuples
- Sets cannot contain duplicate elements
- Therefore, no two tuples in R can be identical
- Therefore, the complete attribute set {A₁, A₂, ..., Aₙ} uniquely identifies each tuple
- Therefore, {A₁, A₂, ..., Aₙ} is a superkey ∎
These proofs establish fundamental guarantees about superkey existence and behavior.
Identifying Superkeys
Given a relation schema and its functional dependencies, we can systematically identify all superkeys. This process is fundamental to database design and analysis.
To verify if a set K is a superkey of R: (1) Compute K⁺, the closure of K under the given functional dependencies. (2) If K⁺ = R (the closure contains all attributes), then K is a superkey. (3) Otherwise, K is not a superkey.
Example: Identifying Superkeys
Consider the relation schema:
Student(StudentID, Name, Email, Major, GPA)
With functional dependencies:
StudentID → Name, Email, Major, GPAEmail → StudentID, Name, Major, GPA
Let's verify which sets are superkeys:
Testing {StudentID}:
- Compute closure: {StudentID}⁺
- Apply FD: StudentID → Name, Email, Major, GPA
- Closure becomes: {StudentID, Name, Email, Major, GPA}
- This equals R, so {StudentID} is a superkey ✓
Testing {Email}:
- Compute closure: {Email}⁺
- Apply FD: Email → StudentID, Name, Major, GPA
- Closure becomes: {Email, StudentID, Name, Major, GPA}
- This equals R, so {Email} is a superkey ✓
Testing {Name}:
- Compute closure: {Name}⁺
- No FD has Name on the left side alone
- Closure remains: {Name}
- This does not equal R, so {Name} is NOT a superkey ✗
Testing {StudentID, Name}:
- By the superset property, since {StudentID} is a superkey, {StudentID, Name} is also a superkey ✓
| Attribute Set | Closure | Is Superkey? | Reasoning |
|---|---|---|---|
| {StudentID} | {StudentID, Name, Email, Major, GPA} | Yes | Closure equals R |
| {Email} | {Email, StudentID, Name, Major, GPA} | Yes | Closure equals R |
| {Name} | {Name} | No | Closure ⊂ R |
| {Major} | {Major} | No | Closure ⊂ R |
| {Name, Major} | {Name, Major} | No | Closure ⊂ R |
| {StudentID, Email} | {StudentID, Name, Email, Major, GPA} | Yes | Superset of {StudentID} |
| {StudentID, Name, Email, Major, GPA} | All attributes | Yes | Trivial superkey |
Counting Superkeys
A natural question arises: How many superkeys does a relation have? The answer reveals why we need the concept of candidate keys to manage the potentially explosive number of superkeys.
If a relation R has n attributes, and K is a minimal superkey (candidate key) with k attributes, then K generates 2^(n-k) superkeys—all subsets of R that contain K. If there are multiple candidate keys, the total count requires inclusion-exclusion to avoid double-counting.
Example: Counting Superkeys
Consider R(A, B, C, D, E) with candidate keys {A, B} and {C, D}:
Superkeys containing {A, B}:
- {A, B}, {A, B, C}, {A, B, D}, {A, B, E}
- {A, B, C, D}, {A, B, C, E}, {A, B, D, E}
- {A, B, C, D, E}
- Total: 2^(5-2) = 2³ = 8 superkeys
Superkeys containing {C, D}:
- {C, D}, {A, C, D}, {B, C, D}, {C, D, E}
- {A, B, C, D}, {A, C, D, E}, {B, C, D, E}
- {A, B, C, D, E}
- Total: 2^(5-2) = 2³ = 8 superkeys
But wait—we've double-counted!
Superkeys containing both {A, B} and {C, D}:
- {A, B, C, D}, {A, B, C, D, E}
- Total: 2^(5-4) = 2¹ = 2 superkeys
By inclusion-exclusion:
- Total superkeys = 8 + 8 - 2 = 14 superkeys
This example shows that even a modest relation with 5 attributes can have 14 superkeys. For larger relations with multiple candidate keys, the number explodes, making the concept of 'candidate key' (minimal superkey) essential for practical database design.
- •Single-attribute key in 10-attribute relation: 2^9 = 512 superkeys from just one candidate key!
- •Two single-attribute keys in 10-attribute relation: 512 + 512 - 256 = 768 superkeys
- •Three single-attribute keys in 10-attribute relation: 512 × 3 - 256 × 3 + 128 = 1,152 superkeys
- •20-attribute relation with 1-attribute key: 2^19 = 524,288 superkeys—over half a million!
Superkeys: Schema vs Data Analysis
A critical distinction exists between identifying superkeys through schema analysis (using functional dependencies) versus data analysis (examining current tuples). This distinction has profound implications for database design correctness.
- •Uses functional dependencies derived from business rules
- •Considers all possible valid database states
- •Identifies semantic constraints inherent to the domain
- •Produces stable results regardless of current data
- •Ensures design correctness for future states
- •Only examines current tuples
- •May find 'accidental' uniqueness
- •Cannot guarantee future state validity
- •Results may change with new data
- •Leads to design errors and constraint violations
Just because {FirstName, Department} is unique in your current data does NOT mean it's a superkey. Tomorrow, you might hire another 'John' in 'Engineering'. Superkeys must be derived from semantic understanding of the domain—not statistical analysis of current data.
Example: The Danger of Data-Based Analysis
Consider this Book table:
| ISBN | Title | Author | Publisher |
|---|---|---|---|
| 978-0-13-468599-1 | Clean Code | Martin | Pearson |
| 978-0-596-51774-8 | JavaScript: Good Parts | Crockford | O'Reilly |
| 978-0-13-235088-4 | Clean Architecture | Martin | Pearson |
Data analysis might suggest:
- {Title} appears unique (currently no duplicates) ❓
- {Author, Publisher} appears unique (currently no duplicates) ❓
But schema analysis reveals:
- {ISBN} is the only true superkey (ISBNs are globally unique by design)
- Different books can (and often do) share titles
- The same author frequently publishes multiple books with the same publisher
The current data is misleading! A proper superkey analysis requires understanding the real-world semantics:
- ISBN is a unique identifier assigned to each book edition
- Authors write multiple books
- Titles can be reused (especially common words)
Lesson: Always derive superkeys from semantic understanding and business rules, not from data coincidences.
The Superkey Hierarchy
Superkeys form a hierarchy based on subset relationships. Understanding this hierarchy is crucial for grasping the relationship between superkeys, candidate keys, and primary keys.
Key observations from the hierarchy:
-
The trivial superkey sits at the top: It contains all attributes and is always a superkey
-
Downward edges represent attribute removal: Moving down removes an attribute while maintaining superkey status
-
Candidate keys are at the bottom: They are minimal superkeys—removing any attribute loses superkey status
-
Paths trace superkey relationships: Any set on a path above a candidate key is also a superkey
-
Not all attribute subsets are superkeys: Only those connected to candidate keys through the hierarchy
Formal relationship:
Let SK(R) denote the set of all superkeys of R. Then:
- If
K ∈ SK(R)andK ⊆ K' ⊆ R, thenK' ∈ SK(R)(upward closure in the lattice) - Candidate keys are the minimal elements of
SK(R) - The trivial superkey is the maximal element of
SK(R)
This structure is called a join semi-lattice under the subset ordering, with candidate keys as the join-irreducible elements.
Understanding the superkey hierarchy helps you: (1) Recognize that finding candidate keys means finding minimal superkeys, (2) Appreciate that superkeys are not arbitrary—they follow strict mathematical rules, (3) See why primary key selection is an important design decision among valid options.
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.