0% found this document useful (0 votes)
23 views15 pages

RDBMSUNIT3

The document discusses data normalization in relational databases. It describes pitfalls of bad database design like redundancy and inability to represent information. It discusses goals of normalization like avoiding redundancy and representing relationships. It provides an example of a faulty database design with redundancy and null values. It describes different types of decomposition like lossless decomposition and dependency preserving decomposition. It also explains concepts like functional dependency, different types of functional dependencies, and database normalization techniques to avoid anomalies.

Uploaded by

muthukannukdvasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views15 pages

RDBMSUNIT3

The document discusses data normalization in relational databases. It describes pitfalls of bad database design like redundancy and inability to represent information. It discusses goals of normalization like avoiding redundancy and representing relationships. It provides an example of a faulty database design with redundancy and null values. It describes different types of decomposition like lossless decomposition and dependency preserving decomposition. It also explains concepts like functional dependency, different types of functional dependencies, and database normalization techniques to avoid anomalies.

Uploaded by

muthukannukdvasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

UNIT3 - DATA NORMALIZATION

3.1.Pitfalls in Relational database Design


Relational database design requires that we find a “good” collection of relational
schemas. A bad design may lead to
— Repetition of information
--Inability to represent certain information
Design Goals for Relational Database
1. Avoid redundant data
2. Ensure that relationships among attributes are represented.
3. Facilitate the checking of updates for violation of database integrity constraints
Example
Consider the relational schema Lending-schema = (branch-name, branch-city, assets,
customer-name, loan- number, amount)
Redundancy
--Data for branch name, branch city, assets are repeated for each loan
that a branch makes
--Wastes space and complicates updating
Null Values
--cannot store information about a branch if no loan exists
--can use null values, but they are difficult to handle.
In the given example the database design is faulty which makes the above pitfalls in
database. So we observe that in relational database design if the design is not good then there
will be faults in database.

3.2 Relational Decomposition

o When a relation in the relational model is not in appropriate normal form then
the decomposition of a relation is required.
o In a database, it breaks the table into multiple tables.
o If the relation has no proper decomposition, then it may lead to problems like
loss of information.
o Decomposition is used to eliminate some of the problems of bad design like
anomalies, inconsistencies, and redundancy.
3.2.1 Types of Decomposition

i)Lossless Decomposition
o If the information is not lost from the relation that is decomposed, then the
decomposition will be lossless.
o The lossless decomposition guarantees that the join of relations will result in the
same relation as it was decomposed.
o The relation is said to be lossless decomposition if natural joins of all the
decomposition give the original relation.

Example:
EMPLOYEE_DEPARTMENT table:

EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME

22 Denim 28 Mumbai 827 Sales

33 Alina 25 Delhi 438 Marketing

46 Stephan 30 Bangalore 869 Finance

52 Katherine 36 Mumbai 575 Production

60 Jack 40 Noida 678 Testing

The above relation is decomposed into two relations EMPLOYEE and DEPARTMENT
EMPLOYEE table:

EMP_ID EMP_NAME EMP_AGE EMP_CITY

22 Denim 28 Mumbai

33 Alina 25 Delhi

46 Stephan 30 Bangalore

52 Katherine 36 Mumbai
60 Jack 40 Noida

DEPARTMENT table

DEPT_ID EMP_ID DEPT_NAME

827 22 Sales

438 33 Marketing

869 46 Finance

575 52 Production

678 60 Testing

Now, when these two relations are joined on the common column "EMP_ID", then the
resultant relation will look like:
Employee ⋈ Department

EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME

22 Denim 28 Mumbai 827 Sales

33 Alina 25 Delhi 438 Marketing

46 Stephan 30 Bangalore 869 Finance

52 Katherine 36 Mumbai 575 Production

60 Jack 40 Noida 678 Testing

Hence, the decomposition is Lossless join decomposition.

ii)Dependency Preserving

o It is an important constraint of the database.


o In the dependency preservation, at least one decomposed table must satisfy
every dependency.
o If a relation R is decomposed into relation R1 and R2, then the dependencies of R
either must be a part of R1 or R2 or must be derivable from the combination of
functional dependencies of R1 and R2.
o For example, suppose there is a relation R (A, B, C, D) with functional dependency
set (A->BC). The relational R is decomposed into R1(ABC) and R2(AD) which is
dependency preserving because FD A->BC is a part of relation R1(ABC).

3.3 Functional dependency


The attributes of a table is said to be dependent on each other when an attribute of a table
uniquely identifies another attribute of the same table.
For example:
Suppose we have a student table with attributes: Stu_Id, Stu_Name, Stu_Age. Here Stu_Id
attribute uniquely identifies the Stu_Name attribute of student table because if we know the
student id we can tell the student name associated with it. This is known as functional
dependency and can be written as Stu_Id->Stu_Name or in words we can say Stu_Name is
functionally dependent on Stu_Id.
Formally:
If column A of a table uniquely identifies the column B of same table then it can represented as
A->B (Attribute B is functionally dependent on attribute A)
3.3.1 Types of Functional Dependencies
 Trivial functional dependency
 non-trivial functional dependency
 Multivalued dependency
 Transitive dependency

i)Trivial functional dependency


The dependency of an attribute on a set of attributes is known as trivial functional dependency
if the set of attributes includes that attribute.
Symbolically: A ->B is trivial functional dependency if B is a subset of A.
The following dependencies are also trivial: A->A & B->B
For example: Consider a table with two columns Student_id and Student_Name.
{Student_Id, Student_Name} -> Student_Id is a trivial functional dependency as Student_Id is
a subset of {Student_Id, Student_Name}. That makes sense because if we know the values of
Student_Id and Student_Name then the value of Student_Id can be uniquely determined.
Also, Student_Id -> Student_Id & Student_Name -> Student_Name are trivial dependencies
too.
ii)Non trivial functional dependency
If a functional dependency X->Y holds true where Y is not a subset of X then this dependency
is called non trivial Functional dependency.
For example:
An employee table with three attributes: emp_id, emp_name, emp_address.
The following functional dependencies are non-trivial:
emp_id -> emp_name (emp_name is not a subset of emp_id)
emp_id -> emp_address (emp_address is not a subset of emp_id)
On the other hand, the following dependencies are trivial:
{emp_id, emp_name} -> emp_name [emp_name is a subset of {emp_id, emp_name}]
iii)Completely non trivial FD:
If a FD X->Y holds true where X intersection Y is null then this dependency is said to be
completely non trivial function dependency.
iv)Multivalued dependency
Multivalued dependency occurs when there are more than one independent multivalued
attributes in a table.
For example: Consider a bike manufacture company, which produces two colors (Black and
white) in each model every year.
bike_model manuf_year color

M1001 2007 Black

M1001 2007 Red

M2012 2008 Black

M2012 2008 Red

M2222 2009 Black

M2222 2009 Red

Here columns manuf_year and color are independent of each other and dependent on
bike_model. In this case these two columns are said to be multivalued dependent on
bike_model. These dependencies can be represented like this:
bike_model ->> manuf_year
bike_model ->> color

v)Transitive dependency
A functional dependency is said to be transitive if it is indirectly formed by two functional
dependencies. For e.g.
X -> Z is a transitive dependency if the following three functional dependencies hold true:
 X->Y
 Y does not ->X
 Y->Z
Note: A transitive dependency can only occur in a relation of three of more attributes. This
dependency helps us normalizing the database in 3NF (3 rd Normal Form).
Example:
Book Author Author_age

Game of Thrones George R. R. Martin 66


Harry Potter J. K. Rowling 49

Dying of the Light George R. R. Martin 66

{Book} ->{Author} (if we know the book, we knows the author name)
{Author} does not ->{Book}
{Author} -> {Author_age}
Therefore as per the rule of transitive dependency: {Book} -> {Author_age} should hold, that
makes sense because if we know the book name we can know the author’s age.
3.4Normalization
Normalization is a process of organizing the data in database to avoid data redundancy,
insertion anomaly, update anomaly & deletion anomaly.
3.4.1Anomalies in DBMS
There are three types of anomalies that occur when the database is not normalized. These
are: Insertion, update and deletion anomaly.
Example: A manufacturing company stores the employee details in a table Employee that has
four attributes: Emp_Id for storing employee’s id, Emp_Name for storing employee’s
name, Emp_Address for storing employee’s address and Emp_Dept for storing the department
details in which the employee works. At some point of time the table looks like this:

Emp_Id Emp_Name Emp_Address Emp_Dept

101 Rick Delhi D001

101 Rick Delhi D002

123 Maggie Agra D890

166 Glenn Chennai D900

166 Glenn Chennai D004

This table is not normalized. The problems that we face when a table in database is not
normalized are,
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 null.
Delete anomaly: Let’s say in future, company closes the department D890 then deleting the
rows that are having Emp_Dept as D890 would also delete the information of
employee Maggie since she is assigned only to this department.
To overcome these anomalies we need to normalize the data.
3.4.2 Types of Normalization
The most commonly used normal forms:

 First normal form(1NF)


 Second normal form(2NF)
 Third normal form(3NF)
 Boyce & Codd normal form (BCNF)
 Fourth normal form(4NF)
 Fifth normal form(5NF)

i)First normal form (1NF)


A relation is said to be in 1NF (first normal form), if it doesn’t contain any multi-valued
attribute. In other words you can say that a relation is in 1NF if each attribute contains only
atomic(single) value only.
As per the rule of first normal form, an attribute (column) of a table cannot hold multiple
values. It should hold only atomic values.
Example: Let’s say a company wants to store the names and contact details of its employees. It
creates a table in the database that looks like this:

Emp_Id Emp_Name Emp_Address Emp_Mobile

101 Herschel New Delhi 8912312390

8812121212 ,
102 Jon Kanpur
9900012222

103 Ron Chennai 7778881212

9990000123,
104 Lester Bangalore
8123450987

Two employees (Jon & Lester) have two mobile numbers that caused the Emp_Mobile field to
have multiple values for these two employees.
This table is not in 1NF as the rule says “each attribute of a table must have atomic (single)
values”, the Emp_Mobile values for employees Jon & Lester violates that rule.
To make the table complies with 1NF we need to create separate rows for the each mobile
number in such a way so that none of the attributes contains multiple values.
Emp_Id Emp_Name Emp_Address Emp_Mobile

101 Herschel New Delhi 8912312390

102 Jon Kanpur 8812121212

102 Jon Kanpur 9900012222

103 Ron Chennai 7778881212

104 Lester Bangalore 9990000123

104 Lester Bangalore 8123450987

ii)Second normal form (2NF)


A table is said to be in 2NF if both the following conditions hold:

 Table is in 1NF (First normal form)


 No non-prime attribute is dependent on the proper subset of any candidate key of table.

An attribute that is not part of any candidate key is known as non-prime attribute.
Example: A school wants to store the data of teachers and the subjects they teach. They create
a table Teacher that looks like this: Since a teacher can teach more than one subjects, the table
can have multiple rows for a same teacher.

Teacher_Id Subject Teacher_Age

111 Maths 38

111 Physics 38

222 Biology 38

333 Physics 40

333 Chemistry 40

Candidate Keys: {Teacher_Id, Subject}


Non prime attribute: Teacher_Age
This table is in 1 NF because each attribute has atomic values. However, it is not in 2NF
because non prime attribute Teacher_Age is dependent on Teacher_Id alone which is a proper
subset of candidate key. This violates the rule for 2NF as the rule says “no non-prime
attribute is dependent on the proper subset of any candidate key of the table”.
To make the table complies with 2NF we can disintegrate it in two tables like this:
Teacher_Details table:

Teacher_Id Teacher_Age

111 38

222 38

333 40

Teacher_Subject table:

Teacher_Id Subject

111 Maths

111 Physics

222 Biology

333 Physics

333 Chemistry

Now the tables are in Second normal form (2NF).


iii)Third Normal form (3NF)
A table design is said to be in 3NF if both the following conditions hold:

 Table must be in 2NF


 Transitive functional dependency of non-prime attribute on any super key should be
removed.

An attribute that is not part of any candidate key is known as non-prime attribute.
In other words a table is in 3NF if it is in 2NF and for each functional dependency X-> Y at
least one of the following conditions hold:

 X is a super key of table


 Y is a prime attribute of table

An attribute that is a part of one of the candidate keys is known as prime attribute.
Example: A company wants to store the complete address of each employee, they create a table
named Employee_Details that looks like this:

Emp_Id Emp_NameEmp_ZipEmp_StateEmp_CityEmp_District

1001 John 282005 UP Agra Dayal Bagh

1002 Ajeet 222008 TN Chennai M-City

1006 Lora 282007 TN Chennai Urrapakkam

1101 Lilly 292008 UK Pauri Bhagwan

1201 Steve 222999 MP Gwalior Ratan

Super keys: {Emp_Id}, {Emp_Id, Emp_Name}, {Emp_Id, Emp_Name, Emp_Zip}…so on


Candidate Keys: {Emp_Id}
Non-prime attributes: all attributes except Emp_Id are non-prime as they are not part of any
candidate keys.
Here, Emp_State, Emp_City & Emp_District dependent on Emp_Zip. Further 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.
To make this table complies with 3NF we have to disintegrate the table into two tables to
remove the transitive dependency:
Employee Table:

Emp_Id Emp_Name Emp_Zip

1001 John 282005

1002 Ajeet 222008

1006 Lora 282007

1101 Lilly 292008

1201 Steve 222999

Employee_Zip table:

Emp_Zip Emp_State Emp_City Emp_District


282005 UP Agra Dayal Bagh

222008 TN Chennai M-City

282007 TN Chennai Urrapakkam

292008 UK Pauri Bhagwan

222999 MP Gwalior Ratan

iv) Boyce Codd normal form (BCNF)


t is an advance version of 3NF that’s why it is also referred as 3.5NF. BCNF is stricter
than 3NF. A table complies with BCNF if it is in 3NF and for every functional dependency
X->Y, X should be the super key of the table.
Example: Suppose there is a company wherein employees work in more than one
department. They store the data like this:

Emp_Id Emp_NationalityEmp_Dept Dept_TypeDept_No_Of_Emp

Production

1001 Austrian and D001 200

planning

1001 Austrian stores D001 250

design and

1002 American technical D134 100

support

Purchasing
1002 American D134 600
department

Functional dependencies in the table above:


Emp_Id -> Emp_Nationality
Emp_Dept -> {Dept_Type, Dept_No_Of_Emp}
Candidate key: {Emp_Id, Emp_Dept}
The table is not in BCNF as neither Emp_Id nor Emp_Dept alone are keys.
To make the table comply with BCNF we can break the table in three tables like this:
Emp_Nationality table:

Emp_Id Emp_Nationality

1001 Austrian

1002 American

Emp_Dept table:

Emp_Dept Dept_TypeDept_No_Of_Emp

Production and planning D001 200

stores D001 250

design and technical


D134 100
support

Purchasing department D134 600

Emp_Dept_Mapping table:

Emp_Id Emp_Dept

1001 Production and planning

1001 Stores

1002 design and technical support

1002 Purchasing department

Functional dependencies:
Emp_Id -> Emp_Nationality
Emp_Dept -> {Dept_Type, Dept_No_Of_Emp}
Candidate keys:
For first table: Emp_Id
For second table: Emp_Dept
For third table: {Emp_Id, Emp_Dept}
This table is now in BCNF as in both the functional dependencies left side part is a key.
v) Fourth normal form (4NF)
o A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-
valued dependency.
o For a dependency A → B, if for a single value of A, multiple values of B exists,
then the relation will be a multi-valued dependency.
Example
STUDENT
STU_ID COURSE HOBBY
21 Computer Dancing
21 Math Singing
34 Chemistry Dancing
74 Biology Cricket
59 Physics Hockey
The given STUDENT table is in 3NF, but the COURSE and HOBBY are two independent
entity. Hence, there is no relationship between COURSE and HOBBY.
In the STUDENT relation, a student with STU_ID, 21 contains two
courses, Computer and Math and two hobbies, Dancing and Singing. So there is a
Multi-valued dependency on STU_ID, which leads to unnecessary repetition of data.
So to make the above table into 4NF, we can decompose it into two tables:
STUDENT_COURSE
STU_ID COURSE
21 Computer
21 Math
34 Chemistry
74 Biology
59 Physics
STUDENT_HOBBY
STU_ID HOBBY
21 Dancing
21 Singing
34 Dancing
74 Cricket
59 Hockey

vi) Fifth normal form (5NF)


o A relation is in 5NF if it is in 4NF and not contains any join dependency and
joining should be lossless.
o 5NF is satisfied when all the tables are broken into as many tables as possible in
order to avoid redundancy.
o 5NF is also known as Project-join normal form (PJ/NF).
Example
SUBJECT LECTURER SEMESTER
Computer Anshika Semester 1
Computer John Semester 1
Math John Semester 1
Math Akash Semester 2
Chemistry Praveen Semester 1
In the above table, John takes both Computer and Math class for Semester 1 but he
doesn't take Math class for Semester 2. In this case, combination of all these fields
required to identify a valid data.
Suppose we add a new Semester as Semester 3 but do not know about the subject and
who will be taking that subject so we leave Lecturer and Subject as NULL. But all three
columns together acts as a primary key, so we can't leave other two columns blank.
So to make the above table into 5NF, we can decompose it into three relations P1, P2
& P3:
P1
SEMESTER SUBJECT
Semester 1 Computer
Semester 1 Math
Semester 1 Chemistry
Semester 2 Math
P2
SUBJECT LECTURER
Computer Anshika
Computer John
Math John
Math Akash
Chemistry Praveen
P3
SEMSTER LECTURER
Semester 1 Anshika
Semester 1 John
Semester 1 John
Semester 2 Akash
Semester 1 Praveen

You might also like