Is table in 2NF

Database Systems
Lecture # 16
Chapter # 10
Normalization
Second Normal Form (2NF)
• A relation that is in 1NF and every non-primary-key
attribute is fully functionally dependent on the
primary key.
• In other words
– A table that is in 1NF and in which the values of
each non-primary-key column can be worked out
from the values in all the columns that make up
the primary key is said to be in 2NF.
2
2NF
• Identify the primary key for the 1NF relation.
• Identify the functional dependencies in the relation.
• If partial dependencies exist on the primary key
remove them by placing then in a new relation along
with a copy of their determinant (Primary Key).
3
Example 1: TempStaffAllocation table
is in 2NF
2NF
: A relation that is in 1NF and every nonprimary-key attribute is fully functionally
dependent on the primary key.
Is
table in 1NF (Yes)
4
Example 1: TempStaffAllocation table
is not in 2NF
5
Example 1: Converting TempStaffAllocation table to 2NF
6
Example(2) 2NF
• EmpNo
• ProNo
• Hours
•
•
•
•
EmpName
ProName
ProLocation
Is table in 2NF ?
: Employee Number (PK).
: Project Number (PK).
: Number of Work
Hours in the project.
: Employee Name.
: Project Name.
: Project Location.
7
Example(2) 2NF
10.3
EmployeePrject (Is table in 1NF) (YES)
EmpNo
ProNo Hours EmpName ProName ProLocation
EmployeePrject (Is table in 2NF)
EmpNo
ProNo Hours EmpName ProName ProLocation
8
Example(2) 2NF
Emp_proj1 (2NF)
EmpNo ProNo
Hours
Emp_proj2 (2NF)
EmpNo
EmpName
Emp_proj3 (2NF)
ProNo
ProName
ProLocation
9
Example(3) 2NF
•
•
•
•
SNo
CNo
SName
CName
: Student Number (PK).
: Course Number (PK).
: Student Name.
: Course Name.
• Is table in 2NF ?
10
Example(3) 2NF
Student (Yes, Student table in 1NF)
SNo
CNo
SName
CName
Student (Is Student table in 2NF)
SNo
CNo
SName
CName
11
Example(3) 2NF
Student (2NF)
SNo
SName
Course (2NF)
CNo
CName
Sts_Crs (2NF)
SNO
CNO
-------------12
Third Normal Form (3NF)
• A relation that is in 1NF and 2NF and in which
no non-primary-key attribute is transitively
dependent on the primary key.
• In other words
– A table that is in 1NF and 2NF and in which
all non-primary-key columns can be worked
out from only the primary key column(s) and
no other columns.
13
2NF to 3NF
• Identify the primary key in the 2NF relation.
• Identify functional dependencies in the relation.
• If transitive dependencies exist on the primary key
remove them by placing them in a new relation along
with a copy of their dominant.
14
Example 3-1 :StaffBranch table is in 3NF
A relation
that is in 1NF and 2NF and in which no nonprimary-key attribute is transitively dependent on the primary
key.
Is
table in 1NF (Yes)
15
Example 3-1 :StaffBranch table is in 3NF
Is
table in 2NF (Yes)
16
Example 3-1 : StaffBranch table is not in 3NF
2NF
3NF
17
Example 3-1 : Converting the StaffBranch table to 3NF
18
Example(3-2) 3NF
•
•
•
•
•
•
EmpNo
EmpName
BDate
Address
DNo
DName
: Employee Number (PK).
: Employee Name.
: Birth Date.
: Address
: Department Number.
: Department Name.
• Is table in 3NF ?
19
Example(3-2) 3NF
Employee (Is Employee table in 1NF) (YES)
EmpNo
EmpName
BDate
Address
DNo
DName
Employee (Is Employee table in 2NF) (YES)
EmpNo
EmpName
BDate
Address
DNo
DName
20
Example(3-2) 3NF
Employee (Is Employee table in 3NF)
EmpNo
EmpName
BDate
Address
DNo
DNam
e
21
Example(3-2) 3NF
Employee in 3NF
EmpNo EmpName BDate Addres DNo
s
Department in 3NF
DNo
DName
22
Example(3-3) 3NF
•
•
•
•
CNo
CName
InsNo
InsOff
: Course Number (PK).
: Course Name.
: Instructor Number.
: Instructor Office.
• Is table in 3NF ?
23
Example(3-3) 3NF
Student (YES table in 1NF)
CNo
CName
InsNo
InsOff
Student (Is table in 2NF) (YES)
CNo
CName
InsNo
InsOff
24
Example(3-3) 3NF
Student (Is table in 3NF)
CNo
CName
InsNo
InsOff
25
Example(3-3) 3NF
Student (3NF)
CNo
CName
InsNo
Instractor (3NF)
InsNo
InsOff
26