Those who are free of resentful thoughts surely find peace. - Buddha
Posted on 14th Jan 2017
Normalization of Database is a multi-step process that puts data into tabular form by removing duplicated data from the relation tables.
Normalization
Here are the most commonly used normal forms:
Let's learn about each of them with an example table as shown below:
Table - Sales
Customer | Item | Shipping Address | Newsletter | Supplier | Supplier Phone | Price |
Alan Smith | Xbox One | 35 Palm St, Miami | Xbox News | Microsoft | (800)BUY-XBOX | 250 |
Roger Banks | PlayStation 4 | 47 Campus Rd, Boston | Play Station News | Sony | (800)BUY-SONY | 300 |
Evan Wilson | Xbox One, PS Vista | 28 Rock Av, Denver | Xbox News, Play Station News | Wholesale | Toll Free | 450 |
Alan Smith | Play Station 4 | 47 Campus Rd, Boston | Play Station News | Sony | (800)BUY-SONY | 300 |
Customer | Item | Shipping Address | Newsletter | Supplier | Supplier Phone | Price |
Evan Wilson | Xbox One, PS Vista | 28 Rock Av, Denver | Xbox News, Play Station News | Wholesale | Toll Free | 450 |
Cust_ID | Customer | Item | Shipping Address | Newsletter | Supplier | Supplier Phone | Price |
at_smith | Alan Smith | Xbox One | 35 Palm St, Miami | Xbox News | Microsoft | (800)BUY-XBOX | 250 |
roger25 | Roger Banks | PlayStation 4 | 47 Campus Rd, Boston | Play Station News | Sony | (800)BUY-SONY | 300 |
wilson | Evan Wilson | Xbox One | 28 Rock Av, Denver | Xbox News | Microsoft | (800)BUY-XBOX | 450 |
wilson | Evan Wilson | PS Vista | 28 Rock Av, Denver | Play Station News | Sony | (800)BUY-SONY | 200 |
am_smith | Alan Smith | Play Station 4 | 47 Campus Rd, Boston | Play Station News | Sony | (800)BUY-SONY | 300 |
Cust_ID | Cust Name | Shipping Address | Newsletter |
at_smith | Alan Smith | 35 Palm St, Miami | Xbox News |
rogger25 | Roger Banks | 47 Campus Rd, Boston | Play Station News |
wilson | Evan Wilson | 28 Rock Av, Denver | Xbox News |
wilson | Evan Wilson | 28 Rock Av, Denver | Play Station News |
am_smith | Alan Smith | 47 Campus Rd, Boston | Play Station News |
Item | Supplier | Supplier Phone | Price |
Xbox One | Microsoft | (800)BUY-XBOX | 250 |
Play Station 4 | Sony | (800)BUY-SONY | 300 |
PS Vita | Sony | (800)BUY-SONY | 200 |
Now we would require a junction table which would map the two table together as show below:
Cust_ID(Primary Key) | Item |
at_smith | Xbox One |
roger25 | Play Station 4 |
wilson | Xbox One |
wilson | PS Vita |
am_smith | Play Station 4 |
In the above table Cust_ID and Item both are the primary keys of respective table. Thus, the above table glues the rows from one table to another.
Cust_ID(Primary Key) | Cust Name | Shipping Address | Newsletter |
at_smith | Alan Smith | 35 Palm St, Miami | Xbox News |
rogger25 | Roger Banks | 47 Campus Rd, Boston | Play Station News |
wilson | Evan Wilson | 28 Rock Av, Denver | Xbox News |
wilson | Evan Wilson | 28 Rock Av, Denver | Play Station News |
am_smith | Alan Smith | 47 Campus Rd, Boston | Play Station News |
Supplier(Primary Key) | Supplier Phone |
Microsoft | (800)BUY-XBOX |
Sony | (800)BUY-SONY |
Item(Primary Key) | Supplier(Foreign Key) | Price |
Xbox One | Microsoft | 250 |
Play Station 4 | Sony | 300 |
PS Vita | Sony | 200 |
Cust_ID(Primary Key ) | Cust Name | Shipping Address | Newsletter |
at_smith | Alan Smith | 35 Palm St, Miami | Xbox News |
rogger25 | Roger Banks | 47 Campus Rd, Boston | Play Station News |
wilson | Evan Wilson | 28 Rock Av, Denver | Xbox News |
wilson | Evan Wilson | 28 Rock Av, Denver | Play Station News |
am_smith | Alan Smith | 47 Campus Rd, Boston | Play Station News |
Cust_ID(Primary Key ) | Cust Name | Shipping Address |
at_smith | Alan Smith | 35 Palm St, Miami |
rogger25 | Roger Banks | 47 Campus Rd, Boston |
wilson | Evan Wilson | 28 Rock Av, Denver |
wilson | Evan Wilson | 28 Rock Av, Denver |
am_smith | Alan Smith | 47 Campus Rd, Boston |
Cust_ID(Primary Key ) | Newsletter |
at_smith | Xbox News |
rogger25 | Play Station News |
wilson | Xbox News |
wilson | Play Station News |
am_smith | Play Station News |
These were the 4 forms of normalization on a given database table and with an example it was explained how it was done. Thanks!
Attributes - detailed data about an entity, such as price, length, name
Cardinality - the relationship between two entities, in figures. For example, a person can place multiple orders.
Entities - abstract data that you save in a database. For example: customers, products.
Foreign key (FK) - a referral to the Primary Key of another table. Foreign Key-columns can only contain values that exist in the Primary Key column that they refer to.
Key - a key is used to point out records. The most well-known key is the Primary Key (see Primary Key).
Normalization - A flexible data model needs to follow certain rules. Applying these rules is called normalizing.
Primary key - one or more columns within a table that together form a unique combination of values by which each record can be pointed out separately. For example: customer numbers, or the serial number of a product.
Good, better, best. Never let it rest. Untill your good is better and your better is best. - St. Jerome