0% found this document useful (0 votes)
25 views27 pages

Normal Form

All about normal form

Uploaded by

N M
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)
25 views27 pages

Normal Form

All about normal form

Uploaded by

N M
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/ 27

Database Management System

Normalization
Presented By
Dr Jasmine Selvakumari Jeya I
Professor & Head/IT
Hindusthan College of Engineering and Technology
Coimbatore – 641 032
[email protected]

1
Normalization
• Normalization of a data is a process of analyzing the given
relation schema based on their Functional Dependency’s and
Primary Key to achieve the desirable properties of
– Minimizing Redundancy
– Minimizing the Insertion, Deletion and Update Anomalies.

2
KEYS
• Keys also help to identify relationships uniquely, and thus
distinguish relationships from each other.
• Various types of keys used in relational model are:
1. Super Key
2. Candidate Key
3. Primary Key
4. Foreign Key

3
1. Super key
• It is a set of one or more attributes within the table that can
be uniquely identify each record within a table. For example –
Consider the student table as follows

Reg_no Roll_no Phone_no Name Marks

16CS101 001 6245869457 AAA 88

16CS102 002 9443358964 BBB 83

16CS103 003 9842156665 CCC 98

16CS104 004 9948562165 DDD 67

4
• The super key can be represented as follows:

Clearly using the (Reg_no) and (Roll_no,Phone_no,Name) we can identify the


records uniquely but (Name, Marks) of two students can be the same, hence this
combination not necessarily help in identifying the record uniquely. 5
2. Candidate key
• The candidate key is a subset of superkey.
• In other words candidate key is a single attribute or least or
minimal combination of attributes that uniquely identify each
record in the table.
• For example, in above given student table, the candidate key is
Reg_no, (Roll_no, Phone_no).
• Thus Every candidate key is superkey but every superkey is not
a candidate key.

6
7
3. Primary key
• The primary key is a candidate key chosen by the database
designer to identify the tuple in the relation uniquely. For
example – Consider the following representation of primary
key in the student table.

8
• Other than the above mentioned primary key, various possible
primary keys can be (Roll_no), (Roll_no, Phone_no). The relation
among superkey, candidate key and primary can be denoted by
• Candidate Key = Super Key – Primary Key
Rules for Primary Key
• 1. The primary key may have one or more attributes.
• 2. There is only one primary key in the relation.
• 3. The value of primary key attribute cannot be NULL.
• 4. The value of Primary key attribute does not get changed.

9
Types of Normal Forms

10
NORMAL FORM DESCRIPTION

INF A relation is in 1NF if it contains an atomic value.

2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully
functional dependent on the primary key.

3NF A relation will be in 3NF if it is in 2NF and no transition dependency exists.

4NF A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-
valued dependency.

5NF A relation is in 5NF if it is in 4NF and not contains any join dependency and
joining should be lossless.

11
First Normal Form
• First Normal Form is defined in the definition of relations
(tables) itself. This rule defines that all the attributes in a
relation must have atomic domains. The values in an atomic
domain are indivisible units.
• As per the rule of first normal form, an attribute (column) of a
table cannot hold multiple values. It should hold only atomic
values.

12
Example
Suppose a company wants to store the names and contact details of its employees

emp_id emp_name emp_address emp_mobile


101 Herschel New Delhi 8912312390
102 Jon Kanpur 8812121212
9900012222
103 Ron Chennai 7778881212
104 Lester Bangalore 9990000123
8123450987
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 &
13
Lester violates that rule.
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

To make the table obeys with 1NF


14
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.

• Prime attribute − an attribute, which is a part of the candidate-key,


is known as a prime attribute.

• Non-prime attribute − an attribute, which is not a part of the


prime-key, is said to be a non-prime attribute. 15
Example
teacher_id subject teacher_age
111 Maths 38
111 Physics 38
222 Biology 38
333 Physics 40
333 Chemistry 40
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.

Candidate Keys: {teacher_id, subject}


Non prime attribute: {teacher_age}
16
• The 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 break it in two table.
17
teacher_details table teacher_subject table

teacher_id teacher_age teacher_id subject


111 38 111 Maths
222 38 111 Physics
333 40 222 Biology
333 Physics
333 Chemistry

18
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.
• An attribute that is a part of one of the candidate keys is known as 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 19
Example
company wants to store the complete address of each employee, they create a table
named employee_details
emp_id emp_name emp_zip emp_state emp_city emp_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
20
candidate keys.
• emp_state, emp_city & emp_district dependent on emp_zip.
• 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 break the
table into two tables to remove the transitive dependency:

21
To make this table complies with 3NF we have to break the table into two tables to
remove the transitive dependency:
employee table employee_zip table

emp_id emp_name emp_zip emp_zip emp_state emp_city emp_district


1001 John 282005 282005 UP Agra Dayal Bagh
1002 Ajeet 222008 222008 TN Chennai M-City
1006 Lora 282007 282007 TN Chennai Urrapakkam
1101 Lilly 292008 292008 UK Pauri Bhagwan
1201 Steve 222999 222999 MP Gwalior Ratan

22
Boyce Codd Normal Form (BCNF)
• It 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:
Company wherein employees work in more than one department. They store the data like
this:
emp_id emp_nationality emp_dept dept_type dept_no_of_emp
1001 Austrian Production and planning D001 200
1001 Austrian stores D001 250
1002 American design and technical support D134 100
1002 American Purchasing department D134 600

23
• 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.

24
emp_nationality table emp_dept table
emp_id emp_nationality emp_dept dept_type dept_no_of_emp
1001 Austrian Production and planning D001 200
1002 American stores D001 250
design and technical support D134 100
Purchasing department D134 600
Functional dependencies:
emp_dept_mapping table
emp_id -> emp_nationality

emp_id emp_dept emp_dept -> {dept_type, dept_no_of_emp}


Candidate keys:
1001 Production and planning
For first table: emp_id
1001 stores
For second table: emp_dept
1002 design and technical support For third table: {emp_id, emp_dept}
1002 Purchasing department This is now in BCNF as in both the functional
25
dependencies left side part is a key.
Normalization Drawbacks
• By limiting redundancy, normalization helps maintain
consistency and saves space.
• But performance of querying can suffer because related
information that was stored in a single relation is now
distributed among several.

26
Thank You !!!

27

You might also like