27
By: Shiraj Mohamed M | MIS | SEUSL NORMALIZATION SHIRAJ MOHAMED M | MIS | SEUSL 1

By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

Embed Size (px)

Citation preview

Page 1: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

1

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

By: Shiraj Mohamed M | MIS | SEUSL

NORMALIZATION

Page 2: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

2

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Basically, normalization is the process of structuring the tables in a database for maximum efficiencyNormalization involves creating tables and establishing relationships between those tables to make the database more flexible by eliminating redundancy and inconstancies.

NORMALIZATION

Page 3: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

3

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SLNORMALIZATION…

• Conceptual Modeling is a subjective process

• Therefore, the schema after the logical database design phase may not be very good (contain redundant data)

• However, there are formalisms to ensure that the schema is good.

• This process is called Normalization

Page 4: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

4

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SLNORMALIZATION…

• Relational database schema = set of relations

• Relation = set of attributes

• How we group the attributes to relations is very important

Page 5: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

5

S H I R A J M O H A M E D M | M I S | S E U S L

SCHEMA REFINEMENT….

DISCUSSED

Page 6: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

6

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Determine Functional dependencies for relation

Find all keys in relation

Normalize the relation

SCHEMA REFINEMENT STEPS

Page 7: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

7

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

There are many Normal Forms proposed to reduce redundancies

Some of the well-known ones are:

1st Normal Form

2nd Normal Form

3rd Normal Form

Boyce-Codd Normal Form

NORMALIZATION….

Page 8: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

8

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Superkey: Set of attributes S in relation R that can be used to identify

each tuple uniquely.

Key: A key is a superkey with the additional property that removal of any attributes from the key will not satisfy

the key condition

REVIEW OF SOME TERMS…

Page 9: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

9

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Candidate Key: Each key of a relation is called a candidate key

Primary Key: A candidate key is chosen to be the primary key

Prime Attribute: an attribute which is a member of a candidate key

Nonprime Attribute: An attribute which is not prime

REVIEW OF SOME TERMS…

Page 10: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

10

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Identify repeating groups of fieldsRemove repeating groups to a separate

tables.Identify the keys for the tables

FIRST NORMAL FORM (1NF)

Page 11: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

11

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Check if all fields are dependent of the whole key

Remove Fields That depend on part of the key

Group Partially dependent fields as a separate table

Name the tablesIdentify keys to the tables

SECOND NORMAL FORM (2NF)

Page 12: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

12

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Remove Fields That Depend on other non key attribute

Group interdependent fields as separate tables , identifies the key and

name the tables

THIRD NORMAL FORM (3NF)

Page 13: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

13

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Cus iD Cus. Name

Cus. Address

Order No

Order Date

Item code

ItDesc Un.price

Qty

100 ABC Kadawatha A-10 10.4.09 C-1 Dhal 125.00

5

100 ABC Kadawatha A-10 10.4.09 C-5 Anchor 250.00

4

100 ABC Kadawatha A-10 10.4.09 C-10 Tea 140.00

6

100 ABC Kadawatha A-10 104.09 F-4 Sunlight 30.00 5

100 ABC Kadawatha A-10 10.4.09 F-7 Vim 98.25 4

100 ABC Kadawatha A-10 10.4.09 F-10 Lux 35.00 5

100 ABC Kadawatha B-40 01.5.09 C-10 Tea 140.00

2

100 ABC Kadawatha B-40 01.5.09 F-4 Sunlight 30.00 1

100 ABC Kadawatha B-40 01.5.09 F-7 Vim 98.25 8

EXAMPLE

Page 14: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

14

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Eliminate any duplicate or repeating columns or groups in the same table.

Since a Customer can place/have many orders, the above table now can be break into two.

Customer Details Table

FIRST NORMAL FORM (1NF)

Cus iD Cus. Name

Cus. Address

100 ABC Kadawatha

Page 15: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

15

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Order Details Table

FIRST NORMAL FORM (1NF) …

Cus iD Order No

Order Date

Item code

ItDesc Un.price

Qty

100 A-10 10.4.11 C-1 Dhal 125.00

5

100 A-10 10.4.11 C-5 Anchor 250.00

4

100 A-10 10.4.11 C-10 Tea 140.00

6

100 A-10 104.11 F-4 Sunlight 30.00 5

100 A-10 10.4.11 F-7 Vim 98.25 4

100 A-10 10.4.11 F-10 Lux 35.00 5

100 B-40 01.5.11 C-10 Tea 140.00

2

100 B-40 01.5.11 F-4 Sunlight 30.00 1

100 B-40 01.5.11 F-7 Vim 98.25 8

Page 16: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

16

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Eliminate redundant data.Now the table structure is improved. But you will notice that the Order Date is repeated.

So take that out from this table.

SECOND NORMAL FORM (2NF)

Cus iD Order No

Order Date

100 A-10 10.4.09

100 B-40 1.5.09

Improved Order Details Table

Page 17: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

17

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Order-Item Table

SECOND NORMAL FORM (2NF)…

Order No

Item code

ItDesc Un.price

Qty

A-10 C-1 Dhal 125.00

5

A-10 C-5 Anchor 250.00

4

A-10 C-10 Tea 140.00

6

A-10 F-4 Sunlight 30.00 5

A-10 F-7 Vim 98.25 4

A-10 F-10 Lux 35.00 5

B-40 C-10 Tea 140.00

2

B-40 F-4 Sunlight 30.00 1

B-40 F-7 Vim 98.25 8

Page 18: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

18

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Eliminate fields that do not depend on the primary key

You can notice that the Item Descriptions, Unit Price are not depend on the Oder No. So easily we can take them out from this

Order-Item table.

Improved Order-Item Table

THIRD NORMAL FORM (3NF)

Page 19: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

19

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

THIRD NORMAL FORM (3NF) …

Order No

Item code

Qty

A-10 C-1 5

A-10 C-5 4

A-10 C-10 6

A-10 F-4 5

A-10 F-7 4

A-10 F-10 5

B-40 C-10 2

B-40 F-4 1

B-40 F-7 8

Improved Order-Item Table

Item code

ItDesc Un.price

C-1 Dhal 125.00

C-5 Anchor 250.00

C-10 Tea 140.00

F-4 Sunlight 30.00

F-7 Vim 98.25

F-10 Lux 35.00

Item Details Table

Page 20: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

20

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Now you will notice that all the details are simplified. So finally you will make

four (4) table to store these order details in the database. The tables will

be as follows

Cus iD Cus. Name

Cus. Address

100 ABC Kadawatha

Customer Details Table

Cus iD Order No

Order Date

100 A-10 10.4.09

100 B-40 1.5.09

Order Details Table

Page 21: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

21

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Order No

Item code

Qty

A-10 C-1 5

A-10 C-5 4

A-10 C-10 6

A-10 F-4 5

A-10 F-7 4

A-10 F-10 5

B-40 C-10 2

B-40 F-4 1

B-40 F-7 8

Order-Item Table

Item code

ItDesc Un.price

C-1 Dhal 125.00

C-5 Anchor 250.00

C-10 Tea 140.00

F-4 Sunlight 30.00

F-7 Vim 98.25

F-10 Lux 35.00

Item Details Table

Page 22: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

22

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

EMP_PROJ

EXAMPLE02

SSN

PNUM HOURS

ENAME PNAME LOC

FD1

FD2

FD3

Page 23: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

23

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

SSN ENAME

EXAMPLE02…

SSN PNUM HOURS

PNUM PNAME PLOC

EP1

EP2

EP3

Page 24: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

24

EXAMPLE02…

ENAME SSN BDATE ADD DNUM DNAME DMGR

EMP_DEPT

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Page 25: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

25

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

ED1

ED2

EXAMPLE02…

ENAME SSN BDATE ADD DNUM

DNUM DNAME DMGR

Page 26: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

26

SH

IR

AJ

MO

HA

ME

D M

| M

IS

| S

EU

SL

Denormalization…Sometime for performance

reasons, database designer may leave the relation in a lower normal form.

This process is known as denormalization.

DENORMALIZATION

Page 27: By: Shiraj Mohamed M | MIS | SEUSL SHIRAJ MOHAMED M | MIS | SEUSL 1

27

S H I R A J M O H A M E D M | M I S | S E U S L

End…