You are on page 1of 6

UNF/0NF (Un-normalized Form)

OrderID CustomerName Address City ProductID Product Price Quantity


1 Keyboard 1000 1
100 Ali Khan 14-D, Gulberg Lahore 2 Mouse 500 1
5 HDMI 200 1
3 Laser Pointer 1400 1
101 Asim Ali 27-N, DHA Lahore
2 Mouse 500 2
102 Babur Awan 33 Defence Karachi 1 Keyboard 1000 2
4 SD Card 800 1
103 Zubair Haider 14, Sector P Islamabad
3 Laser Pointer 1400 1

1NF (First Normal Form)


OrderID CustomerName Address City ProductID Product Price Quantity
100 Ali Khan 14-D, Gulberg Lahore 1 Keyboard 1000 1
2 Mouse 500 1
5 HDMI 200 1
101 Asim Ali 27-N, DHA Lahore 3 Laser Pointer 1400 1
2 Mouse 500 2
102 Babur Awan 33 Defence Karachi 1 Keyboard 1000 2
103 Zubair Haider 14, Sector P Karachi 4 SD Card 800 1
3 Laser Pointer 1400 1

Removing anomaly

OrderID CustomerName Address City ProductID Product Price Quantity


100 Ali Khan 14-D, Gulberg Lahore 1 Keyboard 1000 1
100 Ali Khan 14-D, Gulberg Lahore 2 Mouse 500 1
100 Ali Khan 14-D, Gulberg Lahore 5 HDMI 200 1
101 Asim Ali 27-N, DHA Lahore 3 Laser Pointer 1400 1
101 Asim Ali 27-N, DHA Lahore 2 Mouse 500 2
102 Babur Awan 33 Defence Karachi 1 Keyboard 1000 2
103 Zubair Haider 14, Sector P Karachi 4 SD Card 800 1
103 Zubair Haider 14, Sector P Islamabad 3 Laser Pointer 1400 1
(Making all fields atomic. This introduced redundancy in the table.)

ProductID Product
1 Keyboard
2 Mouse
3 Laser Pointer OrderID ProductID Price Quantity
4 SD Card 100 1 1000 1
5 HDMI 100 2 500 1
100 5 200 1
OrderID Customer Address City 101 3 1400 1
100 Ali Khan 14-D, Gulberg Lahore 101 2 500 2 (Re
101 Asim Ali 27-N, DHA Lahore 102 1 1000 2 mov
102 Babur Awan 33 Defence Karachi 103 4 800 1 ed
103 3 1400 1 the
103 Zubair Haider 14, Sector P Islamabad
repe
ating groups. Now there is no redundancy and all fields are atomic.)

2NF (Second Normal Form)

ProductID Product Price OrderID ProductID Quantity


1 Keyboard 1000 100 1 1
2 Mouse 500 100 2 1
3 Laser Pointer 200 100 5 1
4 SD Card 1400 101 3 1
5 HDMI 500 101 2 2
103 1 2
OrderID Customer Address City 104 4 1
100 Ali Khan 14-D, Gulberg Lahore 104 3 1
101 Asim Ali 27-N, DHA Lahore
102 Babur Awan 33 Defence Karachi
103 Zubair Haider 14, Sector P Islamabad

(Moved the attribute that was partially dependent on the composite key.)
OrderID ProductID Quantity
3NF (Third Normal Form) 100 1 1
100 2 1
ProductID Product Price
100 5 1
1 Keyboard 1000
101 3 1
2 Mouse 500
101 2 2
3 Laser Pointer 200
103 1 2
4 SD Card 1400
104 4 1
5 HDMI 500
104 3 1
OrderID Customer Address CityID CityID City
100 Ali Khan 14-D, Gulberg 1 1 Lahore
101 Asim Ali 27-N, DHA 1 2 Karachi
102 Babur Awan 33 Defence 2 3 Islamabad
103 Zubair Haider 14, Sector P 3 4 Peshawar
5 Quetta

(Removed the indirectly dependent attribute City.)

Note: Attributes in GREEN are Primary Keys.


Definitions: Normal Forms

0NF/UNF
No organization of data.
There are repeating groups.
There is redundancy.

1NF
There are no repeating groups.
Every attribute must be atomic.
There must be no repeating attributes.
There must be no empty Key Field values.

2NF
The database must be in the First Normal Form.
There must not be any partial dependencies.
(All non-prime attributes must be fully dependent on the entire Key Attributes).

3NF
The database must be in the Second Normal Form.
There must not be any indirect dependencies.
(No transitive dependencies).
Definitions: Keys
Primary Key
 An attribute that uniquely identifies a tuple within a relation.

 A candidate key that is most appropriate to become the primary key.


(It must have unique data for each tuple.
It must not have null values.
It must not be editable.
It must not be a primary key in another relation.
There can be only one primary key in a relation.
An attribute that is part of a composite key must not be able to identify a tuple on its own.)
Candidate Key
 An attribute, or set of attributes, that can serve as a primary key.

Non-Prime Attribute
 Any attribute other than the primary key or part of primary key pair.

Non-Key Attribute
 Any attribute that can not be a candidate key.
(It must depend directly on the key attribute(s))

Foreign Key
 An attribute in one relation that references a primary key in another relation.

Composite Key
 Two or more attributes used together to uniquely identify a tuple within a relation.
(An attribute that is part of a composite key must not be able to identify a tuple on its own.)

Secondary or Alternative Key


 Attribute(s) that allow an alternative logical view of data.

You might also like