23
DATABASE NORMALIZATION Ehsan Hamzei

Database Normalization

Embed Size (px)

Citation preview

Page 1: Database Normalization

DATABASE NORMALIZATION

Ehsan Hamzei

Page 2: Database Normalization

NORMALIZATION??

• In RDBs >> For Transactional Purpose >> We Need to minimum the redundancy• In Insert• In Update• In Deletion

• Result in:• Consistency• Performance

Page 3: Database Normalization

FIRST NORMAL FORM

• Each cell contains only a single value.• Each record is unique.• Identified by primary key

Page 4: Database Normalization

EXAMPLE?

Name SSN Address Postal code

Ehsan Hamzei

3920221621 N435 Test alley, Test St, Test Sq, Tehran, Iran

231233213

Ali Hashemi 3242342432 N2131 Work alley, Work St, Work Sq, Mashhad, Iran

324234234

Hassan Mohammadi

2342342344 N2332 Home alley, Home St, Home Sq, LA, USA

324124234

Page 5: Database Normalization

EXAMPLE?

Name SSN Address Postal code

Ehsan Hamzei

3920221621

N435 Test alley, Test St, Test Sq, Tehran, Iran

231233213

Ali Hashemi 3242342432

N2131 Work alley, Work St, Work Sq, Mashhad, Iran

324234234

Hassan Mohammadi

2342342344

N2332 Home alley, Home St, Home Sq, LA, USA

324124234

Page 6: Database Normalization

EXAMPLE?

• Violated !!!• First Name , Last Name• Address >> Building Number, Alley Name, Street Name,

Locality, City, Country

• PK: SSN

Page 7: Database Normalization

EXAMPLE?

• Normalized (First Normal Form)

FN LN SSN BN AN SN LN City Country

Postal code

Ehsan Hamzei 3920221621 N435 Test alley

Test St Test Sq Tehran Iran 231233213

Ali Hashemi 3242342432 N2131 Work alley

Work St Work Sq

Mashhad

Iran 324234234

Hassan Mohammadi

2342342344 N2332 Home alley

Home St Home Sq

LA USA 324124234

Page 8: Database Normalization

EXAMPLE(2)

• Another Example?????

Page 9: Database Normalization

EXAMPLE(2)

• First Normal:

Page 10: Database Normalization

SECOND NORMAL FORM

• Must be first normal!• All non-key fields depend on all

componentsof the primary key.• Guaranteed when primary key is a single

field.

Page 11: Database Normalization

EXAMPLE

• This example is normal in (2nd NF), Because of the single component key!!!!!

FN LN SSN BN AN SN LN City Country

Postal code

Ehsan Hamzei 3920221621 N435 Test alley

Test St Test Sq Tehran Iran 231233213

Ali Hashemi 3242342432 N2131 Work alley

Work St Work Sq

Mashhad

Iran 324234234

Hassan Mohammadi

2342342344 N2332 Home alley

Home St Home Sq

LA USA 324124234

Page 12: Database Normalization

EXAMPLE(2)

• First Normal:

Page 13: Database Normalization

EXAMPLE(2)

• Second Normal:

Page 14: Database Normalization

THIRD NORMAL FORM

•No non-key field depends upon another.• All non-key fields depend only on the

primary key.

Page 15: Database Normalization

EXAMPLE???

FN LN SSN BN AN SN LN City Country

Postal code

Ehsan Hamzei 3920221621 N435 Test alley

Test St Test Sq Tehran Iran 231233213

Ali Hashemi 3242342432 N2131 Work alley

Work St Work Sq

Mashhad

Iran 324234234

Hassan Mohammadi

2342342344 N2332 Home alley

Home St Home Sq

LA USA 324124234

Page 16: Database Normalization

EXAMPLE???

• Violated !!!

• Country & City & LN & SN & BN depend on Postal Code!!!

Page 17: Database Normalization

EXAMPLEFN LN SSN Postal CodeEhsan Hamzei 3920221621 231233213Ali Hashemi 3242342432 324234234Hassan Mohammadi 2342342344 324321234

Postal Code

BN AN SN LN City Country

231233213

N435 Test Alley

Test St Test Sq Tehran Iran

324234234

N2131 Work Allry

Work St Work Sq

Mashhad

Iran

324124234

N2332 Home Alley

Home St

Home Sq

LA USA

Page 18: Database Normalization

EXAMPLE(2)

• First Normal:

Page 19: Database Normalization

EXAMPLE(2)

• Second Normal:

Page 20: Database Normalization

EXAMPLE(2)

• Third Normal Form

Page 21: Database Normalization

SUMMARY

•All Non-Key Column must depend on PK, All Part of PK and Only on PK!!!!!!

Page 22: Database Normalization

REFERENCE

• Data-Base Design (Practical Database Design for Relational Database Management Systems)• Instructional Services at KU Libraries, The University of

Kansas

Page 23: Database Normalization

THANKS