Normalization
Normalization
There are three types of anomalies that occur when the database is not
normalized. These are – Insertion, update and deletion anomaly. Let’s
take an example to understand this.
Example:
The above table is not normalized. We will see the problems that we face when a table
is not normalized.
Update anomaly:
In the above table we have two rows for employee Rick as he belongs
to two departments of the company. If we want to update the address
of Rick then we have to update the same in two rows or the data will
become inconsistent. If somehow, the correct address gets updated in
one department but not in other then as per the database, Rick would
be having two different addresses, which is not correct and would lead
to inconsistent data.
Insert anomaly:
Suppose a new employee joins the company, who is under training and
currently not assigned to any department then we would not be able to
insert the data into the table if emp_dept field doesn’t allow nulls.
Delete anomaly:
Suppose a school wants to store the data of teachers and the subjects
they teach. They create a table that looks like this: Since a teacher can
teach more than one subjects, the table can have multiple rows for a
same teacher.
Here, emp_state, emp_city & emp_district dependent on emp_zip. And, emp_zip is dependent on emp_id that makes non-prime attributes (emp_state, emp_city & emp_district) transitively
dependent on super key (emp_id). This violates the rule of 3NF.
The 3NF Form
The table is not in BCNF as neither emp_id nor emp_dept alone are keys.
The BCNF Form
Source