DBMS - Normalization - QA
DBMS - Normalization - QA
Algorithm:
Example:
Assume a relation schema R = (A, B, C) with the set of functional dependencies F = {A → B,
B → C}. Now, we can find the attribute closure of attribute A as follows;
Step 1: We start with the attribute in question as the initial result. Hence, result = A.
Step 2: Take the first FD A → B. Its left hand side (i.e, A) is in the result, hence the right hand
side can be included with the result. This lead to result = AB.
Step 3: Take the second FD B → C. Its left hand side (i.e, B) is in the result (or subset of result),
hence the right hand side can be included with the result. Now, result = ABC.
We have no more attributes. Hence the algorithm exits. As the result, A+ includes all the attributes
of relation R. now we would say A+ is ABC. And, A is one of the keys of the relation R.
Solution:
Let us find the closure for the left hand side (LHS) attributes of given set of functional
dependencies.
Let us take the FD BC → A to check whether the LHS BC forms a candidate key or not.
We know Result = How? Description
BC BC Given
BC BCA BC→ A If we know BC,
then we can
derive A
uniquely as per
the reflexivity
rule, hence
result = BCA
BCA BCAD AC→D From the
previous step
we know
attribute A,
and by the FD
AC → D the
result becomes
ABCD which is
equal to R.
Hence, BC is a
candidate key
We derived all the other candidate keys in the same way as stated above and given in the table
below:
BC, AC, and CD are the candidate keys for the given relation.
Question 2:
For the following relation schema R and set of Functional Dependencies F:
R(A,B,C,D,E), F = {AC → E, B → D, E → A}
List all candidate keys.
Answer: From the given set F of functional dependencies, it is very evident that B and C must be
in the candidate key as they are not present in the Right Hand Side (RHS) of the given set of FDs.
Hence, at first we can check for BC as the candidate key as follows;
If you know B, then you know B and D through FD B → D. Along with this, if you know C, then
you know BCD. That is, BC → BCD. B and C together cannot determine A and E, so BC cannot
be a candidate key.
Then we can try with the attributes that are present in the LHS like B and C. First let us take A.
Then we have,
ABC → ABCDE. So, ABC is a candidate key.
Now we shall try with the other LHS attribute E. Then we have,
BCE → ABCDE. So, BCE is another candidate key.
Checking BCA and BCE, we see that both of them are candidate keys.
Type 2: Normalization
Question: Normalize upto 3NF.
Is User_Personal in 3NF?
To verify this we need to check the 3NF properties;
Property 1 – Table should be in 2NF.
Property 2 – There should not be any Transitive Dependencies in the table.
UserID → Zip,
Zip → City State
Solution:
Decompose User_Personal. For this, we can use the functional dependencies Zip → City State and
UserID → U_email Fname Lname City State Zip.
As a result, we can have the following tables (primary keys are underlined);
A borrower is identified with an unique borrower_id, and has only one address. Borrowers can
have multiple simultaneous loans, but they always have different request dates. The borrower can
make multiple repayments on the same day, but not more than one repayment per loan per day.
a) State a key (candidate key) for Repayment.
b) Make the normalization to BCNF. Show the steps.
Answer:
Answer a):
From the given information, we can derive the following set of functional dependencies;
Borrower_id → name [given: every borrower is identified with an unique id]
From the above set of FDs, it is evident that we can uniquely identify all the other attributes of
Repayment table, if we know the values of (borrower_id, requestdate, repayment_date). That is,
Answer b):
1. We can easily derive name and address of every borrower if we know the borrower_id from the
FDs Borrower_d → name, and Borrower_id → address.
2. We can derive the loanamount if we know borrower_id, and requestdate from the FD
Borrower_id, Requestdate → loanamount.
Hence, the relation Repayment is not in 2NF. To convert it into a 2NF relation, we can decompose
Repayment into the following relations;
From the derived FDs, we know that all these tables are in 2NF.
Yes. There are no transitive dependencies present in the above tables’ set of functional
dependencies. Hence, we would say that all these tables are in 3NF.
Question: A table has fields F1, F2, F3, F4, and F5, with the following functional dependencies:
F1->F3
F2->F4
(F1,F2)->F5
in terms of normalization, this table is in
(a) 1NF (b) 2NF (c) 3NF (d) None of these
Question:
Let R(A,B,C,D,E,P,G) be a relational schema in which the following FDs are known to hold:
AB->CD
DE->P
C->E
P->C
B->G
The relation schema R is
(a) in BCNF (b) in 3NF, but not in BCNF
(c) in 2NF, but not in 3NF (d) not in 2NF
Type 3: Find
whether the given decomposition is Lossless or lossy
decomposition
Question:
Suppose you are given a relation R(A,B,C,D). let us assume that set of functional dependencies F
= { B → C, D → A} and R is decomposed into R1(B,C), and R2(A,D).
(a) Find the candidate key(s) for R. (b) State whether or not the proposed decomposition of R into
smaller relations is a good decomposition and briefly explain why or why not.
Solution:
a) To find the candidate keys, we have to find the closure of attributes of LHS (left hand side) of
all functional dependencies. If the closure includes all the attributes of the given relation, then that
attribute (or set of attributes) is the candidate key.
B+ = BC. It does not include all attributes of R.
D+ = DA. It does not include all attributes of R.
(BD)+ = BCDA. It includes all attributes of R, hence BD is the candidate key.
b) The decomposition of R into R1 and R2 is lossy because there is no common attribute between
R1 and R2 (R1∩R2 = ∅). Hence, the join of R1 and R2 will result in Cartesian product of these
two relations which is not the base relation R.
Type 4: Minimal/Canonical Cover (Irreducible Set)
Find the minimal cover of the set of functional dependencies given; {A → BC, B → C, AB → D}
Solution:
Minimal cover:
Definition 1:
A minimal cover of a set of FDs F is a minimal set of functional dependencies Fmin that is
equivalent to F. There can be many such minimal covers for a set of functional dependencies
F.
Definition 2:
A set of FDs F is minimum if F has as few FDs as any equivalent set of FDs.
1. Right Hand Side (RHS) of all FDs should be single attribute. So we write F as F1, as follows;
F1 = {A → B, A → C, B → C, AB → D}
Extraneous attribute is a redundant attribute on the LHS of the functional dependency. In the set
of FDs, on AB → D has more than one attribute in the LHS. Hence, we check one of A and B is
extraneous or not.
First we check whether A is extraneous or not. To do that, we need to find the closure of the
remaining attribute B with respect to F1.
B+ = BC.
Now we check whether B is extraneous or not. To do that, we need to find the closure of the
remaining attribute A with respect to F1.
A+ = ABCD.
F2 = {A → B, A → C, B → C, A → D}
F3 = {A → B, B → C, A → D}