Any subset of attributes of a table that can uniquely identify all the tuples of that table is known as a Super key. Its different from the primary and candidate keys in the sense that only the minimal superkeys are the candidate/primary keys.
This means that from a super key when we remove all the attributes that are unnecessary for its uniqueness, only then it becomes a primary/candidate key. So, in essence, all primary/candidate keys are super keys but not all superkeys are primary/candidate keys. By the formal definition of a Relation(Table), we know that the tuples of a relation are all unique. So the set of all attributes itself is a super key.
Counting the possible number of superkeys for a table is a common question for GATE. The examples below will demonstrate all possible types of questions on this topic.
Super keys of(a1 a2) + Super keys of(a1 a3) – Super keys of(a1 a2 a3)
⇒ 2(n – 2) + 2(n – 2) – 2(n – 3)
Example 8: Let a Relation R have attributes {a1, a2, a3,…,an} and the candidate keys are “a1”, “a2”, “a3” then the possible number of super keys?
In this question, we have 3 different candidate keys. Tackling problems like these are shown in the diagram below.
→ |A1 ∪ A2 ∪ A3| = |A1| + |A2| + |A3| – |A1 ∩ A2| – |A1 ∩ A3| – |A2 ∩ A3| + |A1 ∩ A2 ∩ A3|
= (superkeys possible with candidate key A1) + (superkeys possible with candidate key A2) + (superkeys possible with candidate key A3) – (common superkeys from both A1 and A2) – (common superkeys from both A1 and A3) – (common superkeys from both A2 and A3) + (common superkeys from both A1, A2 and A3)
= 2(n-1) + 2(n-1) + 2(n-1) – 2(n-2) – 2(n-2) – 2(n-2) + 2(n-3)
Example 9: A relation R(A, B, C, D, E, F, G, H)and set of functional dependencies are
CH → G,
A → BC,
B → CFH,
E → A,
F → EG
Then how many possible super keys are present ?
Step 1: First of all, we have to find what the candidate keys are:-
as we can see in given functional dependency D is missing but in relation, D is given so D must be a prime attribute of the Candidate key.
A+ = E+ = B+ = F+ = all attributes of a relation except D
So, Ck’s are = AD, BD, ED, FD
Step 2: Find superkeys due to single candidate key
there is a two possibility of attribute either we select or not hence there will be 2 chances so,
A_ _D_ _ _ _ = _ B_ D_ _ _ _ = _ _ _ DE _ _ _ = _ _ _ D_F_ _ = 26
Step 3: Find superkeys due to combination of two CK’s
so,
n(AD ∩ BD) = n(AD ∩ ED) = n(AD ∩ FD) = n(BD ∩ ED) = n(BD ∩ FD) = n(ED ∩ FD) = 25
Step 4: Find supekeys due to combination of three CK’s
so,
n(AD ∩ BD ∩ ED) = n(AD ∩ ED ∩ FD) = n(ED ∩ BD ∩ FD) = n(BD ∩ FD ∩ AD) = 24
Step 5: Find superkeys due to all so,
n(AD ∩ BD ∩ ED ∩ FD) = AB_DEF_ _ = 23
so according to inclusion- exclusion principle :-
|W ∪ X ∪ Y ∪ Z| = |W| + |X| + |Y| + |Z| – |W ∩ X| – |W ∩ Y| – |W ∩ Z| – |X ∩Y| – |X ∩ Z| – |Y ∩ Z| + |W ∩ X ∩ Y| + |W ∩ X ∩ Z| + |W ∩ Y ? Z| + |X ∩ Y ∩ Z| – |W ∩ X ∩ Y ∩ Z|
#Supekeys = 4 * 26 – 6 * 25 + 4 * 24 – 23 = 120
62 videos|66 docs|35 tests
|
1. What is a superkey in DBMS? |
2. How many possible superkeys can exist in DBMS? |
3. What is the difference between a superkey and a candidate key in DBMS? |
4. How can superkeys be used in database design? |
5. Can a table have multiple candidate keys? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|