Docsity

database normalisation, Slides of Computer Science

Partial preview of the text

Download database normalisation and more Slides Computer Science in PDF only on Docsity!

Understanding Normalization

Definition: The process of producing a simpler and more reliable database structure by creating a suitable set of relations for storing data. Purpose:  (^) Simplifies database design complexities.  (^) Produces consistent, reliable relations.  (^) Eliminates processing problems and data redundancy.  (^) Brings the database to a "consistent state." Why do we need normalization? To avoid the problems like Redundancy of data, wastage of storage and data inconsistency etc..

Functional Dependency

 (^) Functional dependency is a relationship between two attributes.  (^) It states that if the value of one attribute is known, it is possible to obtain the value of another attribute.  (^) It means that attribute B is functionally dependent on attribute A if the value of A determines the value of B. The functional dependency is written as follows: A B Determinant (A): The attribute on the left. Determined (B): The attribute on the right.

Example:

RollNo StudentName, Class, Email

StudentName, Class, Email are functionally dependent on RollNo and its value can be

obtained If the value of RollNo is known.

Normal Forms

The process of Normalization works through different stages known as Normal forms. These stages are:

  • 1 st^ Normal Form
  • 2 nd^ Normal Form
  • 3 rd^ Normal Form
  • (^) Boyce-Codd Normal Form
  • 4 th^ Normal Form
  • 5 th^ Normal Form First Normal Form  (^) Atomic Values: Every Intersection of row and column must contain atomic (single) values only.  (^) No Repeating Groups: Sets of repeating data items must be removed.  (^) Unique Rows: Each field should contain only one value per record.

Conversion Method1: Fill the blank fields with proper data so that each row represents a unique attribute combination.

Conversion Method2: The repeating groups are removed by a creating a separate relation for the repeating group. The

repeating data is stored in the new relation.

Partial Dependency

A dependency in which non-key attributes depend on part of the primary key is called Partial Dependency.

Composite Primary Key: (StudentID + CourseID) Functional Dependencies: StudentID StudentName CourseID CourseName

Why is it Partial Dependency?

StudentName depends only on StudentID AND CourseName depends only on CourseID They do not depend on the complete primary key. Therefore, this relation contains Partial Dependency

Problems Caused by Partial Dependency:

  1. Insertion Anomaly: Cannot insert a new course unless a student is enrolled.
  2. Deletion Anomaly: Deleting a student record may also remove course information.
  3. Update Anomaly: If a student name changes, it must be updated in multiple rows

Second Normal Form (2NF)

A relation is in 2NF if:

  1. It is already in 1NF.
  2. Every Non-key attribute is fully functionally dependent on the primary key.

Goal: Remove Partial Dependencies(where an attribute depends only on part of a composite key).

Separate the table into smaller tables StudentID StudentNam e 101 Ali 102 Sara CourseID CourseName C1 DBMS C2 OOP StudentID CourseID 101 C 101 C 102 C Course Table Student Table Enrollment Table Result:

  • (^) Redundancy is reduced.
  • (^) Anomalies are removed.
  • (^) Relation becomes closer to 2NF.

BCNF (Boyce-Codd Normal Form) is an advanced version of 3NF. A table is in BCNF if:

  • (^) It is already in 3NF
  • (^) Every determinant is a candidate key.

Boyce-Codd Normal Form (BCNF)

 (^) If an attribute determines another attribute, then it must be a candidate key. Example: Teache r Subjec t Room Ahmad DBMS R Ahamd OOP R Sara Java R Not in BCNF Functional Dependencies: Teacher, Subject Room Teacher Room Problem: Teacher determines Room. But Teacher is not a candidate key. Therefore, the relation violates BCNF.

Converting Relation into BCNF

Teacher Room Ahmad R Sara R This Table stores: which Room belongs to which teacher. TeacherSubject Table Teache r Subject Ahmad DBMS Ahmad OOP Sara Java TeacherRoom Table This Table stores: which subject is taught by which teacher. Result: There will be no anomalies. Example: If Ahmad’s room changes from R1 TO R3: We update only ONE row. Not multiple rows.

Example to Understand Fourth NF

Studen t Hobby Languag e Ali Readin g English Ali Readin g Urdu Ali Readin g English Ali Readin g Urdu Problem:

  • (^) Hobby and language are stored together.
  • (^) Data is repeated many times.
  • (^) Redundancy increases. The relation is NOT in 4NF. Before 4NF: After Converting to 4 NF: Stuudent Hobby Ali Cricket Ali Reading Separating the table Stuudent Language Ali English Ali Urdu StudentHobby Table StudentLanguage Table Result:
  • (^) Reduce Redundancy
  • (^) Makes Updates Easier  (^) Adding a new Hobby does not affect languages.  (^) Adding a new language does not affect the Hobbies.

Fifth Normal Form (5NF)

A table is in Fifth Normal Form (5NF) if:

  • (^) It is already in 4NF.
  • It contains no join dependency.  (^) A relation should not be divided into smaller tables unless it can be joined back without losing information. Join Dependency Join dependency occurs when:
  • (^) A table can be divided into smaller tables
  • (^) And the original table can be recreated by joining those tables  (^) 5NF removes unnecessary redundancy caused by complex many-to-many relationships.