TOPICS (Click to Navigate)

Pages

Saturday, August 4, 2018

Find candidate key and normalize the relation into 2nf and 3nf

Find candidate key and normalize the relation into 2nf and 3nf

Question:
A relation R is defined as follows.
R = (name, street, city, state, postal_code)
Here, name is unique, and for any given postal code, there is just one city and state.

  • Give a set of FDs for this relation.
  • What are the candidate keys?
  • Is R in 3NF? 2NF? Explain why?
  • If R is not in 3NF, normalize it into 3NF relations.

Solution:
a) Set of functional dependencies;
It is given that Name is unique. Hence, it determines all the other attributes.
name → street, name → city, name → state, name → postal_code
also given that postal_code is unique for a city and state. Hence, postal_code can determine city and state uniquely.
postal_code → city, postal_code → state.
So, set F of functional dependencies for the given relation R is;
F = {name → street, name → city, name → state, name → postal_code, postal_code → city, postal_code → state}

b) What are the candidate keys?
Candidate key is the minimal super key that can uniquely identify all the other attributes of a given relation.
In our case, the attribute name is said to be unique and determines all the other attributes of R. Hence, name is the candidate key.

c) Is R in 3NF? 2NF? Explain why?
2NF
A relation is said to be in 2NF if no partial key dependencies exist.
In our problem, name is the candidate key and there is no possibility for partial key dependencies (it may occur only if the key is composite). Hence, R is in 2NF.
3NF
A relation is said to be in 3NF if it does not have any non-key dependencies.
In our problem, postal_code determines city and state [postal_code → city, postal_code → state] and postal_code is a non-key attribute. So, R is not in 3NF.

d. If R is not in 3NF, normalize it into 3NF relations.
R is not in 3NF. So we need to decompose R into two or more relations. We can do this using the functional dependencies that violate the 3NF property.
In our problem, the attribute postal_code violates 3NF property by uniquely determining the city and state attributes. Hence, we can decompose R by taking these attributes into a separate table as follows;

R1 = (postal_code, city, state) with FDs { postal_code → city, postal_code → state} and postal_code as the candidate key.
R2 = (name, street, postal_code) with FDs { name → street, name → postal_code} and name as the candidate key.
Now the relations R1 and R2 are in 3NF.

***********







Normalize the tables into second and third normal forms solved examples

normalization exercises solved

2nf

3nf

find candidate keys

convert 2nf relation to 3nf relation

convert unnormalized into normalized relation




No comments:

Post a Comment