Normalization: Mrs. CH - Swathi
Normalization: Mrs. CH - Swathi
Mrs. Ch.Swathi
• Normalization in DBMS
In DBMS, database normalization is a process of making the database consistent by-
3
1. First Normal Form (1NF)
A given relation is called in First Normal Form (1NF) if each cell of the table contains only an atomic value.
OR
A given relation is called in First Normal Form (1NF) if the attribute of every tuple is either single valued or a null
value.
Example
The following relation is not in 1NF-
• This can be done by rewriting the relation such that each cell of the table contains only one value.
NOTE
• By default, every relation is in 1NF.
• This is because formal definition of a relation states that value of all the attributes must be atomic.
2 . Second Normal Form (2NF)
A given relation is called in Second Normal Form (2NF) if and only if -
Example-
Consider a relation- R ( V , W , X , Y , Z ) with functional dependencies-
VW → XY
Y→V
WX → YZ
VW , WX , WY
From here,
• Prime attributes = { V , W , X , Y }
• Non-prime attributes = { Z }
• This is because there exists no dependency where incomplete candidate key determines any non-
prime attribute.
A partial dependency is a dependency where few attributes of the candidate key determines non-prime
attribute(s).
OR
A partial dependency is a dependency where a portion of the candidate key or incomplete candidate key
determines non-prime attribute(s).
In other words,
NOTE-
• To avoid partial dependency, incomplete candidate key must not determine any non-prime attribute.
A given relation is called in Third Normal Form (3NF) if and only if-
Transitive Dependency
NOTE-
Example-
• Prime attributes = { A , B , C , D , E }
• There are no non-prime attributes
Now,
Example-
Consider a relation- R ( A , B , C ) with the functional dependencies-
A→B
B→C
C→A
The possible candidate keys for this relation are- A , B , C
Now, we can observe that RHS of each given functional dependency is a candidate key.
Given below are the examples of super keys since each set can uniquely identify each student in the
Student table-
• ( roll , name , gender , age , address , class , section )
• ( class , section , roll )
• (class , section , roll , gender )
• ( name , address )
NOTE
All the attributes in a super key are definitely sufficient to identify each tuple uniquely in the given relation but
all of them may not be necessary.
2. Candidate Key-
A minimal super key is called as a candidate key.
OR
A set of minimal attribute(s) that can identify each tuple uniquely in the given relation is called as a candidate
key.
Example-
NOTES-
• All the attributes in a candidate key are sufficient as well as necessary to identify each tuple uniquely.
• Removing any attribute from the candidate key fails in identifying each tuple uniquely.
• The value of candidate key must always be unique.
• The value of candidate key can never be NULL.
• It is possible to have multiple candidate keys in a relation.
• Those attributes which appears in some candidate key are called as prime attributes.
3. Primary Key-
A primary key is a candidate key that the database designer selects while designing the database.
OR
Candidate key that the database designer implements is called as a primary key.
NOTES-
Candidate keys that are left unimplemented or unused after implementing the primary key are called as alternate keys.
OR
Unimplemented candidate keys are called as alternate keys.
5. Foreign Key-
•An attribute ‘X’ is called as a foreign key to some other attribute ‘Y’ when its values are dependent on the
values of attribute ‘Y’.
•The attribute ‘X’ can assume only those values which are assumed by the attribute ‘Y’.
•Here, the relation in which attribute ‘Y’ is present is called as the referenced relation.
•The relation in which attribute ‘X’ is present is called as the referencing relation.
•The attribute ‘Y’ might be present in the same table or in some other table.
Example-
Here, t_dept can take only those values which are present in dept_no in Department table since only those departments
actually exist.
NOTES-
6. Partial Key-
•Partial key is a key using which all the records of the table can not be identified uniquely.
•However, a bunch of related tuples can be selected from the table using the partial key.
Example-
E1 Suman Mother
E1 Ajay Father
E2 Vijay Father
Son
E2 Ankush
Here, using partial key Emp_no, we can not identify a tuple uniquely but we can select a bunch of tuples
from the table.
7. Composite Key-
A primary key comprising of multiple attributes and not just a single attribute is called as a composite key.
8. Unique Key-
Example-
Example-
Mobile Number of students in a class where every student owns a mobile phone.
Secondary key is required for the indexing purpose for better and faster searching.