Keys and Candidate-Key Constraints for : Solving the “ cannot be …” Problem
We are given a relation Students(StudentID, StudentName, StudentE-mail, StudentAge, CPI) with tuples:
| StudentID | StudentName | StudentE-mail | StudentAge | CPI |
|---|---|---|---|---|
| 2345 | Shankar | shankar@math | X | 9.4 |
| 1287 | Swati | swati@ee | 19 | 9.5 |
| 7853 | Shankar | shankar@cse | 19 | 9.4 |
| 9876 | Swati | swati@mech | 18 | 9.3 |
| 8765 | Ganesh | ganesh@civil | 19 | 8.7 |
We are asked: for to be the key for this instance, the value should not be equal to: (i) 18, (ii) 19, (iii) 15, (iv) 20.
A key (and specifically the combination given) must satisfy uniqueness for that attribute set: no two different rows may have the same pair.
Key terms:
- Key
- Candidate Key
- Uniqueness Constraint
- Functional Dependency
Key idea
Check the existing pairs and see when a collision occurs.
Current pairs (ignoring and CPI for key-check):
- Tuple 1:
- Tuple 2:
- Tuple 3:
- Tuple 4:
- Tuple 5:
So, to keep as a key, must not equal any other existing pair.
A collision can only happen if:
- , which implies .
No other existing tuple has .
Thus, the only forbidden value among the options is , i.e., option (ii) 19.
Ensure $(StudentName, StudentAge)$ is a Key
- 1Step 1
Extract from each tuple; the only unknown is the first tuple’s age .
- 2Step 2
You obtain: , , , , plus .
- 3Step 3
A collision happens if equals an existing pair.
- 4Step 4
Only has the same StudentName, so equality requires .
- 5Step 5
Therefore, to keep uniqueness, should not be (option (ii)).
Pro Tip
When checking if an attribute set is a key, ignore all non-key attributes and focus purely on whether the key-attribute values are unique across rows. If any two rows share the same key-attribute values, it’s not a key.
Common Mistake
Don’t use uniqueness to decide keyness. Even if is unique, still must be unique by its own values.
Mental Workflow for Key-Constraint Problems
Extract
Step AWrite the value pairs/tuples for the proposed key attributes."
Compare
Step BLook for identical pairs among rows."
Solve Constraint
Step CIf an unknown exists (here ), compute the values that would cause a collision."
Pick the Option
Step DSelect the option value that must be excluded to maintain uniqueness."
Collision Check for with Existing Pair
If , then collides and violates key uniqueness.
Why other values are fine
Knowledge Check
For to be a key, what must be true for any two tuples?