Showing posts with label Normalization. Show all posts
Showing posts with label Normalization. Show all posts

Monday, February 6, 2017

Normalization solved exercise bcnf 1

Normalize up to BCNF, Boyce-codd normal form normalization, steps in normalizing a relation to bcnf relation


Question:

Normalize the following table. Show all work and clearly indicate the primary and foreign keys.
R(elevator_no, building_no, building_name, capacity, staff_no, first_name, last_name, date_examined) with the following functional dependencies:
1. elevator_no building_no,capacity
2. building_no building_name
3. staff_no first_name,last_name
4. elevator_no,staff_no date_examined
Normalize table R up to BCNF.

Solution:
1NF – The table R is already in first normal form because of atomic attributes. All the attributes of R are atomic.

2NF – Second normal form is about elimination of partial key functional dependency. To proceed further, we need to find the key for R. For that we need to find the how to find attribute closure for all the left hand side attributes of the given functional dependencies.
elevator_no+
Result = building_no, capacity from the FD elevator_no building_no,capacity
           = building_no, capacity, building_name - from building_no building_name
Result of elevator_no+ does not include all attributes of R. Hence, elevator_no cannot be the key of R.
staff_no+
Result = first_name, last_name – from the FD staff_no first_name,last_name
Result of staff_no+ does not include all attributes of R. hence, staff_no cannot be the key of R.
(Elevator_no, staff_no)+
Result = date_examined
from the FD elevator_no,staff_no date_examined
            = date_examined, building_no, capacity
from elevator_no building_no,capacity
            = date_examined, building_no, capacity, building_name
            from building_no building_name
            = elevator_no, building_no, building_name, capacity, staff_no, first_name, last_name, date_examined
            from staff_no first_name,last_name
The result includes all the attributes of R for (Elevator_no, staff_no)+. Hence, (Elevator_no, staff_no) is the key (composite key) of R.
Do we have partial key dependencies in R?
Yes. The following are the partial key dependencies.
elevator_no building_no,capacity
staff_no first_name,last_name
The reason is, both elevator_no and staff_no are parts of the key of R. They can uniquely identify some of the non-key attributes. Because of these partial key dependencies, R is not in 2NF.
To convert R into 2NF relations, we need to decompose R on partial key dependencies. Thus, we get the following relations; (primary keys are underlined)
R1 (elevator_no, building_no, capacity, building_name)
          From FDs elevator_no building_no,capacity and building_no building_name
R2 (staff_no, first_name, last_name)
From FD staff_no first_name,last_name
R3 (elevator_no, staff_no, date_examined)
From FD elevator_no,staff_no date_examined
 in R3 elevator_no is one foreign key referencing R1, and staff_no is another foreign key referencing the relation R2.
Are R1, R2, and R3 in 2NF?
Yes. In all the relations, all non-key attributes are fully-functionally dependent on the primary keys.

3NF – Third normal form is about elimination of non-key dependencies, that is, a functional dependency with a non-key attribute is dependent on another non-key attribute.
Do we have non-key dependencies in R1?
Yes. See below;
R1 (elevator_no, building_no, capacity, building_name)
          F = {elevator_no → building_no,capacity and building_no → building_name}
In R1 we have a non-key dependency building_no → building_name, that is the non-key attribute building_no uniquely determines the other non-key attribute building_name.
R1 is in 2NF because of no partial key dependencies and not in 3NF because of non-key dependencies.
To convert R1 into 3NF relations, decompose R1 on non-key dependencies. Thus, we get the following relations;
R11 (elevator_no, building_no, capacity)
From FD elevator_no building_no, capacity
R12 (building_no, building_name)
From FD building_no building_name a non-key dependency.
in R12 building_no is the primary key and in R11 building_no is the foreign key referencing the relation R12.
Do we have non-key dependencies in R11 and R12?
No. Hence, R11 and R12 are in 3NF.
Do we have non-key dependencies in R2 and R?
No. Hence, R2 and R3 are in 3NF.

BCNF – The determinants in a FD should be the key for the relation.
Are R11, R12, R2, and R3 are in BCNF?
Yes. Each relation have only one functional dependency. And the determinants of the functional dependencies are the primary keys. Hence the relations R11, R12, R2, and R3 are in BCNF.
***************

Go to - 1NF,    2NF,    3NF,    BCNF







Friday, December 16, 2016

Find the correct BCNF decomposition for a given database table

Find the correct BCNF decomposition for a given database table


Question:

11. Consider the relation R(A, B, C, D, E) with set of functional dependencies F = {A → B, C → D}. Let us assume that R is in 1NF. Which of the following is the correct BCNF decomposition of R?


(a) R1 (A, C, D, E) and R2 (A, B)
(b) R1 (A, B, C, E) and R2 (C, D)
(c) R1 (A, B), R3 (C, D), and R3 (A, C, E)
(d) All of the above.



Answer:

(c) R1 (A, B), R3 (C, D), and R3 (A, C, E)

Discussion:

It is given that R is in 1NF. To proceed further, we need to find the key of R.
Where to start?
From the given set F of functional dependencies, we would understand that the attributes A, C and E are not present in the RHS of functional dependencies. Hence, we shall start with finding the closure of (ACE). Refer here to know how to find closure of anattribute.

Find (ACE)+
Result = ACE
Result = ABCE (from the functional dependency A → B)
Result = ABCDE (from the FD C → D)
At this stage, result = ABCDE which is equal to R. Hence, ACE is a super key.
Is (ACE) a candidate key?
To check this, we need to find the closure of proper subset of (ACE). If the proper subset does not contain another super key, then ACE is a candidate key.
Proper subset of (ACE) consists of (A), (C), (E), (AC), (CE), and (AE). Find the closure for each component. None of them forms the super key. Hence, (ACE) is the candidate key.

Is R in 2NF?
No. The reason is the partial dependency A → B. So, we need to decompose R using the FD A → B. We shall get relations as follows;
R1 (A, B) – it is in 2NF.
R2 (A, C, D, E) – it is not in 2NF because of the violating FD C → D.
We shall break R2 as follows;
R2 (C, D) – it is in 2NF.
R3 (A, C, E) – it is in 2NF.

Are R1, R2 and R3 are in 3NF?
3NF – Transitive dependencies must not present in a relation.
Neither of R1, R2, and R3 have transitive dependencies. Hence, all these relations are in 3NF.

Are R1, R2 and R3 are in 3NF?
BCNF – the LHS of all FDs should be candidate key.
For R1, A → B is the only FD and A is the candidate key.
For R2, C → D is the only FD and C is the candidate key.
For R3, no FDs. Hence, all attributes (ACE) form the key.
So, R1, R2, and R3 are in BCNF.




         Previous Question                                                                                Next Question


Monday, December 12, 2016

Database Normalization - Home Page

Database Normalization, Normal forms 1NF, 2NF, 3NF and BCNF explained, Solved exercises for normalization, links to external sources, Examples

Database Normalization

Database normalization - solved exercises, university questions

Database normalization process explained, solved exercises in database normalization, normalization concepts university exam questions, online quizzes etc.

Exercises

Featured Content

Multiple choice questions in Natural Language Processing Home

MCQ in Natural Language Processing, Quiz questions with answers in NLP, Top interview questions in NLP with answers Multiple Choice Que...

All time most popular contents

data recovery