0% found this document useful (0 votes)
2 views

Normalization (1)

Normalization is a process that organizes data in databases to reduce redundancy and eliminate anomalies by dividing larger tables into smaller ones linked by relationships. It involves several forms, including First Normal Form (1NF), Second Normal Form (2NF), and Third Normal Form (3NF), each with specific rules to ensure data integrity and logical storage. Keys, including primary and foreign keys, are essential for uniquely identifying records and establishing relationships between tables.

Uploaded by

zeki.mama21.21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Normalization (1)

Normalization is a process that organizes data in databases to reduce redundancy and eliminate anomalies by dividing larger tables into smaller ones linked by relationships. It involves several forms, including First Normal Form (1NF), Second Normal Form (2NF), and Third Normal Form (3NF), each with specific rules to ensure data integrity and logical storage. Keys, including primary and foreign keys, are essential for uniquely identifying records and establishing relationships between tables.

Uploaded by

zeki.mama21.21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Normalization

Dr Anil Kumar
Normalization
• Normalization is a process for assigning attributes to entities.
• It reduces data redundancies and helps eliminate the data anomalies.
• Normalization rules divides larger tables into smaller tables and links them using
relationships.
• The purpose of Normalization in SQL is to eliminate redundant (repetitive) data
and ensure data is stored logically.
• Purpose:
• To Eliminate the redundant or useless data.
• To Reduce the complexity of the data.
• To Ensure the relationship between tables as well as data in the tables.
Database Normalization
• Assume, a video library maintains a database of movies rented out.
• Without any normalization in database, all information is stored in one table as
shown below.
1NF (First Normal Form) Rules
• Each table cell should contain a single value.
• Each record needs to be unique.
• The above table in 1NF-
• Before we proceed let’s understand a few things —
• What is a KEY in SQL?
• A KEY in SQL is a value used to identify records in a table uniquely.
• An SQL KEY is a single column or combination of multiple columns used to uniquely
identify rows or tuples in the table.
• SQL Key is used to identify duplicate information, and it also helps establish a
relationship between multiple tables in the database.
• Note: Columns in a table that are NOT used to identify a record uniquely are called
non-key columns.
• A primary is a single column value used to identify a database record uniquely.
• It has following attributes
• A primary key cannot be NULL
• A primary key value must be unique
• The primary key values should rarely be changed
• The primary key must be given a value when a new record is inserted.
• What is Composite Key?
• A composite key is a primary key composed of multiple columns used to identify
a record uniquely
• In our database, we have two people with the same name Robert Phil, but they
live in different places.

• Hence, we require both Full Name and Address to identify a record uniquely. That
is a composite key.
• Let’s move into second normal form 2NF
2NF (Second Normal Form) Rules
• Rule 1- Be in 1NF
• Rule 2- Single Column Primary Key that does not functionally dependent on any
subset of candidate key relation
• It is clear that we can’t move forward to make our simple database in
2nd Normalization form unless we partition the table above.
• We have divided our
• Table 1 contains member information.
• Table 2 contains information on movies rented.
• We have introduced a new column called Membership_id which is the primary key for
table 1.
• Records can be uniquely identified in Table 1 using membership id
• Database – Foreign Key
• In Table 2, Membership_ID is the Foreign Key

• Foreign Key references the primary key of another Table! It helps connect your
Tables
• A foreign key can have a different name from its primary key
• It ensures rows in one table have corresponding rows in another
• Unlike the Primary key, they do not have to be unique. Most often they aren’t
• Foreign keys can be null even though primary keys can not
• Why do you need a foreign key?
• Suppose, a novice inserts a record in Table B such as

• You will only be able to insert values into your foreign key that exist in the unique key in
the parent table. This helps in referential integrity.
• The above problem can be overcome by declaring membership id from Table2 as
foreign key of membership id from Table1
• Now, if somebody tries to insert a value in the membership id field that does not exist in
the parent table, an error will be shown!
• What are transitive functional dependencies?
• A transitive functional dependency is when changing a non-key column, might
cause any of the other non-key columns to change
• Consider the table 1. Changing the non-key column Full Name may change
Salutation.

• Let’s move into 3NF


3NF (Third Normal Form) Rules
• Rule 1- Be in 2NF
• Rule 2- Has no transitive functional dependencies
• To move our 2NF table into 3NF, we again need to again divide our table.
• 3NF Example
• Below is a 3NF example in SQL database:
• We have again divided our tables and created a new table which stores Salutations.
• There are no transitive functional dependencies, and hence our table is in 3NF
• In Table 3 Salutation ID is primary key, and in Table 1 Salutation ID is foreign to primary key in Table 3
• Problem: this table is not very efficient with storage.
• This design does not protect data integrity
• Third, table does not scale well
First Normalization

• We now have two rows for single book.


• Additionally, we would be violating the 2nd Normal form
• A better solution to our problem would be to separate the table, Author and
Subject table, to store our information, removing that information from book
table.
• Each table has a primary key, used for joining tables when querying the data.
• A primary key value must be unique with in the table, and a primary key is also
an index, which speeds up data retrieval based on primary key.
• Now to define relationships between the tables

You might also like