Skip to main content

Normalization in Oracle database #Diksha Oracle Training Centre


                            Normalization in Oracle database.

  

Hello Everyone ,

Today I am going to discuss about Normalization . Before starting this topic  I suggest you to please go through my previous blogs for your reference. Let’s discuss about Normalization. Normalization rules divide larger tables into smaller tables and links them using relationships. Normalization in Database is very important as it is the process of taking data from a problem and reducing it to a set of relations while ensuring data integrity and eliminating data redundancy.  In Simple word Normalization is a database design technique that reduces data redundancy and eliminates undesirable characteristics like Insertion, Update and Deletion .

Below are the Key Points in Normalization.

Data Integrity : All of the data in the database are consistent , and satisfy all integrity constraints.

Data Redundancy : If  data in the database can be found in two different locations( Direct redundancy) or if data can be calculated from other data items (indirect redundancy) then the data is said to contain redundancy.

Note: Data Integrity we already discussed in my previous logs for keys etc you can take reference .

Without Normalization in SQL we may face below issues.

Insertion anomaly: It happens when we cannot insert data to the table without the presence of another attribute.

Update anomaly:  It is a data inconsistency that results from data redundancy and a partial update of data.

Deletion Anomaly: It happens when certain attributes are lost because of the deletion of other attributes.

SQL with Normalization :SQL is the language that is used to interact with the database. To initiate any interaction the data present in the database has to be of Normalized Form. Else we cannot proceed further as it results in anomalies.

Normalization in SQL will enhance the distribution of data. Now let’s discuss about each and every Normal Form with simple examples.

 

1NF (1st Normalisation Form)

 

2NF (2nd Normalisation Form)

 

3NF (3rd Normalisation Form)

 

BCNF (Boyte –Codd Normal Form)

 

Note: The Theory of Data Normalization in SQL is still being developed further. For example, there are discussions even on 6th Normal Form. But the most practical applications, normalization achieves its best is 3rd Normalization Form.

 

1NF (First Normalisation Form) : 1NF deals with the shape of the record type.

 

Rules of 1NF:

Each table cell should contain a single value.

Each record needs to be unique.

In 1NF a single cell cannot hold multiple values. If a table contains a composite or multi-valued attribute, it violates the First Normal Form.

Note : Key and Constraint I already discussed in my previous blogs so for reference you can see that , but hope you are aware about keys and constraints.

 

Let’s take example from  below table for 1NF which violate 1NF.



 

In the above table, we can clearly see that the cell number column has two values. Thus it violated the 1st NF. To make 1NF we need to modify the value of the table. Below table is 1NF.



 

Applying this, we have achieved atomicity and also each and every column have unique values. And its follow First Norm Form.

 

2NF (2nd Norm Form):  The first condition in the 2nd NF is that the table has to be in 1st NF. The table also should not contain partial dependency. Here partial dependency means the proper subset of candidate key determines a non-prime attribute. To understand in a better way see the below example.

See the below table.


 

This table has a composite primary key Emplyoee ID, Department ID. The non-key attribute is Department Name. In this case, Department Name only depends on Department ID, which is only part of the primary key. Therefore, above table does not satisfy the 2NF.


Make this table as Second Normal Form, we need to break the table into two parts.

Two tables are Below :

 


 

 


 

 

 

 

As you see now we have removed the partial functional dependency that we initially had. Now, in the table, the column department_name is fully dependent on the primary key of that table, that is department_id.

 

3NF (3rd Normal Form)

 

Same rule applies as before i.e, the table has to be in 2NF before proceeding to 3NF.

Rules for 3NF is as below:

 

A relation in 3NF if, and only if  , it is in 2 NF and there are no transitive functional dependencies. Transitive Functional dependencies arise:

 

When one non-key attribute is functionally dependant on another non-key attributes and there is redundancy in data attribute.

 

Let understand this more clearly with example:

 

 


 

 

In the above table, enrollment_no determines subject ID, and subject ID determines Subject. Therefore, enrollment_no determines Subject using subject ID. This implies that we have a transitive functional dependency, and this  does not follow the third normal form(3NF).

 

To achieve third normal form, we need to divide the table in two part as below:

 



 

Here you can see from the above tables all the non-key attributes are now fully functional dependent only on the primary key. In the first table, columns Student Name, Subject ID and Address are only dependent on enrollment_no. In the second table, Subject is only dependent on Subject ID. This follow 3NF(3rd Normal Form).

 

Boyce Cod Normal Form (BCNF)

 

This is also known as 3.5 NF. It’s the higher version 3NF . BCNF to address certain types of anomalies which were not dealt with 3NF.

 

Before proceeding to BCNF the table has to satisfy 3rd Normal Form.

 

In BCNF if every functional dependency A → B, then A has to be the Super Key of that particular table.

 

See the below table:

 

 


 

 

One student can enrol for multiple subjects.There can be multiple Trainer teaching one subject And, For each subject, a Trainer is assigned to the student .In this table, all the normal forms are satisfied except BCNF.

 

Because As you can see enrollment_no,  and Subject form the primary key, which means the Subject column is a prime attribute. But, there is one more dependency, Trainer_name → Subject.

 

And while Subject is a prime attribute, Trainer_name is a non-prime attribute, which is not allowed by BCNF.

 

To satisfy the BCNF, we will be dividing the table into two parts. One table will hold Stud_ID which already exists and newly created column Trainer_ID.





 

By Applying this we are satisfied the BCNF.

 

This is all about Normalization in SQL .I think you have now clear picture about Normalization.  I suggest you to see my below blog where in archive folder you can able to see constraints and different key in and  SQL command for your reference .

https://dikshaoracletraining.blogspot.com/

Please go through this blog carefully and let me know if you have any doubts as Normalization plays important in database and this blog is important for fresher candidate who is preparing for interview.

Thanks.

Comments

Post a Comment

Popular posts from this blog

SQL and Classification of SQL in Oracle Database #Diksha Oracle Training Centre

  SQL and Classification of SQL in Oracle Database.   SQL is Structured Query Language , which is used for storing, manipulating and retrieving data stored in a relational database .SQL is the standard language for RDBMS. All the Relational Database Management Systems (RDMS) like Oracle, MySQL, Sybase, Informix, IBM DB2 and Microsoft SQL Server use SQL as their standard database language. Oracle is one of the more secured database as compared to other databases. Importance of   SQL : SQL and PL/SQL is a backend process where all data is stored and retrieved in GUI which created either by any programming languages like Java, C++, PHP etc. so we need to have very secure database so that there will be no impact for users. SQL allows users to access data in the relational database management systems. SQL is used to communicate with a database.SQL and PL/SQL allows users to create and drop databases tables , views , stored procedures , functions , packages , trigger etc. SQL allows

Materialized View uses and Benefits in Database #DOTC_Mdb

Materialized View uses and Benefits in Database. Hello Everyone, Today we will discuss about Materialized view as it’s play important role in database. We already discussed about Simple Views and complex views in my previous blog. Before Materialized view go through my previous blog which related to simple view. https://dheeraj60.blogspot.com/2020/05/benefits-of-creating-and-using-view-in.html As we know View is not a database object and not like table which is stored in database, but view can be created from base table a view is an SQL statement that’s stored in the database. This statement, or view, has a name.A view looks and acts a lot like a table. It has columns and rows, and can be included in SELECT queries just like a table. In other word we can say View is a virtual/logical table which is basically used for security purpose. Let’s understand   about   Materialized view : A materialized view is a view that stores the results of the view’s query. Whenever you query the ma

Top 50 Interview Questions On SQL and PL/SQL #DOTC_Mdb

                    Top 50 Interview Questions On SQL and PL/SQL. Today we will Discuss Top 50 interview questions and answers of SQL and PL/SQL which is frequently asked in interview.     Question 1: What is SQL and Classification of SQL? Answer SQL is a Structure Query Language which is vastly used in RDBMS database like Oracle, Sybase, DB2 , Microsoft SQL server etc.   Classification of SQL is as below: DDL (Data Definition Language):  Commands are  create , alter , drop , truncate etc DML (Data Manipulation Language) : Commands are  insert,update and delete . TCL (Transaction Control Language ) : Commands are  Commit , Rollback and Save point. DCL (Data Control Language) : Commands are Grant , Revoke Question 2:    What is meant by Joins? What are the types of join? Answer Joins are basically used to extract/get data from multiple tables using some common columns or conditions and also by using alias to fulfill the condition.   There are various types of Joins as li