Showing posts with label first normal form. Show all posts
Showing posts with label first normal form. Show all posts

Monday, 18 June 2012

First Normal Form

Hey ! As said previously, now, we will discuss types of database normalization. And we're gonna begin with First Normal form.
[Note: I suggest you to visit my earlier post discussing the concept of normalization in general, if haven't done already.]
The two criteria to be satisfied for a relational table to be having First Normal form (without going to exact academic definition) are:
  1. The table should have a primary key (A column with unique and non-null values. Since it contains unique values, primary key values can identify each records of table.)
  2. There should not be two or more columns containing same type of values.
To understand better, let's take an example of table EMP_DETAIL storing details of employees in an office as shown.

As you can see an employee can have more than one phone number,so there are three columns in the table storing phone numbers.
Let's see whether this table qualifies for first normal form or not.
It satisfies the first criterion, it has a column "ID" congaing unique and non-null values. So, does this table have first normal form? NO, the second criterion isn't satisfied here, as the table has three columns "Phone1", "Phone2", and "Phone3" which contain same type of values phone numbers.
Now, if we want to normalize this table to first normal form, we have to make sure it fulfills the second criteion as well. To do so, we can separate columns containing
same types of values (i.e. phone number columns in this example) and create a separate table for them. After making this structural change, we'll be having two tables as shown here.

Observe both the tables, Here the new table contains two columns, "ID" and "Phone" . And ID is foreign key in new table to make a primary - foreign key relation with main table. Now, we have the two tables with fiest normal form. In main table, the primary key is ID, while in new second table, the primary key is composite i.e. both "ID" and "Phone" together make primary key in second table.

Now, here is a important tip I use to keep remembering the first normal form: To make first normal form from a denormalized table, we create one-to-many relationship between main table and new second table. Look the example again, we have done same thing.

Hope, this post was of some benefit to you. We will discuss the second normal form in the next post.

Bye !!!

Friday, 15 June 2012

Database Normalization

Hi guys !!! Database Normalization is must to be known and understood by any IT professional who is working with relational databases.
For most of the guys getting started to learn the basic concepts, this topic proves a little hard to grasp. In my case, it haunted me. Even after understanding it many times, I just kept forgetting it.

So, keeping that in mind, we will try to discuss the Normalization in way easy to understand and remember as well. In this post, we will first get  the basic idea, what is normalization , its relevance and how it is achieved. It's types will be discussed in other posts.

Now, In the nutshell, normalizaion is about two things.
  1. Removal of data redundancy (repetition of same data) over same fields in the records in database table.
  2. Sensible data dependencies. To make it understand better, its like having a table in which all the columns are related.
Based on different level of the two factors mentioned above, we have different types of Database Normalization.
We First , Second , Third, fourth and fifth normal form. The first three normal forms are most practically used forms of normalization.

Here are some points highlighting its significance of Normalization.
  • Removal of redundancy --> uniqueness of records in table, Saving of storage space and Reduction in time to write or insert data into database
  • Sensible data dependencies --> Elimination of unnecessary relationships between columns within/among the database tables. And Retrieving data becomes simple and logical in terms of the query writing.
  • Database tables become easy to maintain.
After getting the basic idea and significance of Normalization, Let's know how it is achieved. Basically, it's done by separating data by creating new table(s) having primary - foreign key relationships with main table. The intent here is to achieve some level of the two factors I mentioned in the beginning.

I'll be back with more posts discussing First, Second and Third normal form.

See you then, Bye !!!