Saturday 14 May 2016

Normalization in PHP

Normalization

It is a technique to organizing a data in database. It is a systematically approach of decomposite table to remove data dependency.


Normalization is used for mainly two purpose.


  1. Eliminate redundant and useless data. 
  2. Answering data dependances make sense.

Ex. Data is logicaly stops.

1st normalization form:- 

How to convert table in first normal for?
  1. Repeating group of information from the table.
  2. Each column must have a unique value.


Without Normalization:- 

S_name
Address
Subject
Abc
Canada
Maths, computer
Xyz
Washington
Computer

 1st normal form:-

S_name
Address
Subject
Abc
Canada
Maths
Abc
Canada
Computer
Xyz
Washington
Computer

2nd normalization form

How to convert table in second normal form?
  1. Table must have in first normal form.
  2. Remove partial dependency:- any non prime attribute depend on the part of the prime attribute that is call prime partial dependency.

1st normal form:- stud_table

Primary key

Part of P_K

S_id
S_name
Sub_id
Sub_name
1
Abc
1
maths
2
xyz
2
computer

2nd normal form:- stud_table

Primary key

S_id
S_name
1
Abc
2
xyz

Sub_table

Primary Key

Foreign key
Sub_id
Sub_name
S_id
1
Maths
1
2
computer
2

3rd normal form:-

How to convert table in third normal form?

  1. Table must be in a second normal form.
  2. Remove Transitive dependency:- Any non prime attribute depend on another non prime attribute this is called transitive dependency.

2nd normal form:- Product_table

Primary Key



p_id
p_name
category
sub_category
1
K4 note
mobile
lenovo

3rd normal form:- Product_table

Primary key

p_id
p_name
1
K4 note

Category_table

Primary Key

Foreign key
c_id
category
p_id
1
mobile
1

Sub_category_table

Primary Key

Foreign key
s_id
sub_category
c_id
1
lenovo
1

If you want to work on database in any language you must be the database in a normalize form.

No comments:

Post a Comment