Normalisation
Normalisation
Second Normal Form (2NF): A table is 2NF, if it is 1NF and every non-key column is fully dependent on the primary key.
•It should be in the First Normal form.
•And, it should not have Partial Dependency.
Third Normal Form (3NF): A table is 3NF, if it is 2NF and the non-key columns are independent of each others.
•It is in the Second Normal form.
•And, it doesn't have Transitive Dependency.
Boyce and Codd Normal Form is a higher version of the Third Normal form. This form deals with certain type of anomaly that
is not handled by 3NF. A 3NF table which does not have multiple overlapping candidate keys is said to be in BCNF.
•must be in 3rd Normal Form
•and, for each functional dependency ( X → Y ), X should be a super Key.
Fourth Normal Form (4NF)
A table is said to be in the Fourth Normal Form when,
•It is in the Boyce-Codd Normal Form.
•And, it doesn't have Multi-Valued Dependency.
Normalization is a process of organizing the data in database to avoid data redundancy, insertion anomaly, update
anomaly & deletion anomaly.
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, if at a point of time the 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.
Normalization First normal form (1NF)
Here are the most commonly used normal forms: As per the rule of first normal form, an attribute (column) of a
table cannot hold multiple values. It should hold only atomic
First normal form(1NF)
values.
Second normal form(2NF)
Example:
Third normal form(3NF)
Boyce & Codd normal form (BCNF)
8812121212
102 Jon Kanpur
9900012222
9990000123
104 Lester Bangalore
8123450987
Two employees (Jon & Lester) are having two mobile numbers so the company stored them in the same field as you
can see in the table above.
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 should have the data like this:
111 Maths 38
111 Physics 38
222 Biology 38
333 Physics 40
333 Chemistry 40
To make the table complies with 2NF we can break it in two tables like this:
teacher_id teacher_age teacher_id Subject
Third Normal form (3NF)
111 38 111 Maths
A table design is said to be in 3NF if both the following conditions
hold:
teacher_id Subject 111 Physics
Table must be in 2NF
333 Physics An attribute that is a part of one of the candidate keys is known
as prime attribute.
333 Chemistry
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.
Example: Suppose there is a company wherein employees work in more than one department. They store the
data like this:
emp_nationali dept_ty dept_no_of_e Functional dependencies in the table above:
emp_id emp_dept
ty pe mp emp_id -> emp_nationality
Production and
1001 Austrian
planning
D001 200 emp_dept -> {dept_type, dept_no_of_emp}
1001 Austrian stores D001 250 Candidate key: {emp_id, emp_dept}
design and technical
1002 American
support
D134 100 The table is not in BCNF as neither emp_id nor emp_dept
1002 American
Purchasing
D134 600
alone are keys.
department
To make the table comply with BCNF we can break the
table in three tables like this:
Functional dependencies:
emp_id -> emp_nationality
emp_id emp_dept emp_dept -> {dept_type, dept_no_of_emp}
1001 Production and planning
Candidate keys:
1001 stores
For first table: emp_id
1002 design and technical support
For second table: emp_dept
1002 Purchasing department
Fourth normal form (4NF) is a level of database normalization where there are no non-trivial multivalued dependencies
other than a candidate key. It builds on the first three normal forms (1NF, 2NF and 3NF) and the Boyce-Codd Normal
Form (BCNF).
Properties – A relation R is in 4NF if and only if the following conditions are satisfied:
It should be in the Boyce-Codd Normal Form (BCNF).
the table should not have any Multi-valued Dependency.
Example – Consider the database table of a class whaich has two relations R1 contains student ID(SID) and student
name (SNAME) and R2 contains course id(CID) and course name (CNAME).
Table – R1(SID, SNAME ) Table – R2(CID, CNAME)
SID SNAME CID CNAME
S1 A C1 C
S2 B C2 D
Example – Agent->->Company
Table – R1 Agent->->Product
Table – R2 Table – R3
Company->->Product
1. Insert a new field ‘Designation’ in the employee table having the following properties - Text(10),
required ,Not Null, validation rule (“ Officer” or “Clerk” or “Manager” or “Supervisor” )
2. Enter value to ‘designation’ field in employee table .
3. Select all employees from employee table displaying their name , code, department name, depart location,
Basic and Date of joining.
4. Select employee name, Age, Doj whose name starts with ‘s’.
5. Select employees whose age greater than 45.
6. Select employees name ,basic, Department code and location whose has joined before the year 2000.
7. Select employees name, age , location and designation where designation =“Manager”.
8. Find the list of employees who do not belong to “Manager” or “Clerk”.
9. Update employee table as da=10%of basic, hra=15%of basic, ma=12%of basic and tax=20%of basic
10. Update employee table as totsalary=[basic]+[da]+[hra]+[ma]-[tax].
11. Select employees name , location , designation and totsalary where totsalary> 24000.
12. Perform the above query with the same criteria along with designation=“clerk” .
.
Assignment -3( Maketable , Append & Delete)
1. Create a table ‘duplicate Employee’ from ‘Employee’ using ‘make table query.’
2. Create a table ‘selective Employee’ from ‘Employee’ (all fields) using ‘make table query’ where
Ecode=“e004” or totsalary>=10000.
3. Create a new table ‘combined’ having the fields Ecode, Ename,Dcode, DoJ, Totsalary from
Employee and Department using ‘Make table query’.
4. Create a blank table ‘duplicate Department’ having same field name and data type of
‘Department’.
5. Insert records from ‘Department’ table to ‘duplicate Department’ table using append query
where Dcode>10 .
6. Delete records from the ‘selective Employee’ using delete query applying a suitable date
criteria.
7. Append records to ‘selective Employee’ table from ‘Employee’ where the Ecode >e004.
8. Delete records from ‘selective Department’ table where Dcode = ”30”.
9. Select records from Employee table where Employee name starts with ‘s’.
10.Select those Employees name, phone no. ,address, ecode and dcode whose totsalary <25000
or tax > 2000.