Sie sind auf Seite 1von 9

Normalization:

 Need for normalization:


 to eliminate data anomalies
 to reduce data redundancy

1) Data anomalies:

Insert anomalies: It may not be possible to store some data unless some other data is
stored as well.

Delete anomalies: It may not be possible to delete some data without losing some other
data.

Update anomalies: If one of the repeated attribute is updated, inconsistency is created


unless all copies are simultaneously updated.

2) Normal Forms:
1NF - First Normal form. Remove the repeating group of data.
2NF - Second Normal form. Remove the partial functional dependency.
3NF - Third Normal form. Remove the transitive functional dependency.

BCNF - Every determinant is a candidate key


4NF - Fourth Normal form. Remove the multi-valued dependency.
5NF - Lose -less joining

Example 1.

The relation given below lists doctor/patient appointment data. A patient is given an
appointment at a specific time and date with a doctor for a particular surgery allotted to
particular theatre.

Doctor Doctor Patient Patient Date-of- time Surgery Theatre


No Name No Name appointment No Number
D1 John P1 William 19-11-2009 9.00am S1 T1
D1 John P2 Lim 19-11-2009 10.00am S1 T1
D2 Stephen P3 Raj 19-11-2009 11.00am S2 T1
D2 Stephen P3 Raj 26-11-2009 9.00am S5 T1
D3 Wong P2 Lim 20-11-2009 11.00am S3 T2
D3 Wong P4 Abdul 21-11-2009 9.00am S3 T2
D4 Teo P5 Johnson 21-11-2009 11.00am S4 T2

i) Explain the data anomalies present in the given relation

Insertion Anomaly: Inserting a Doctors detail require a patient detail that may not
be available.

Deletion Anomaly: Deleting a patient record with PatientNo=5 will remove the
Modification Anomaly: Changing the Theatre Number T1 to T3, requires changes
in four relations.

ii) Identify two candidate keys present in the given relation and choose one as the
primary key.

Candidate keys are


i) ( DoctorNo, PatientNo, Date-of-appointment)

ii) (DoctorNo, PatientNo, SurgeryNo)

Primary key : ( DoctorNo, PatientNo, Date-of-appointment)

iii) Identify all the functional dependencies present in the given relation and hence
do 1NF , 2NF and 3NF

Functional dependencies:
a) DoctorNo  DoctorName

b) PatientNo  PatientName

c) SurgeryNo  TheatreNumber

d) ( DoctorNo, PatientNo, Date-of-appointment)  time

First Normal Form: Remove the repeating group of data.


Doctor
DoctorNo Doctor Name
D1 John
D2 Stephen
D3 Wong
D4 Teo

R1
DoctorNo PatientNo PatientNam Date-of-appointment time SurgeryNo TheatreNumbe
e r
D1 P1 William 19-11-2009 9.00am S1 T1
D1 P2 Lim 19-11-2009 10.00am S1 T1
D2 P3 Raj 19-11-2009 11.00am S2 T1
D2 P3 Raj 26-11-2009 9.00am S5 T1
D3 P2 Lim 20-11-2009 11.00am S3 T2
D3 P4 Abdul 21-11-2009 9.00am S3 T2
D4 P5 Johnson 21-11-2009 11.00am S4 T2
2NF Remove the Partial functional dependency.

Doctor
DoctorNo DoctorName
D1 John
D2 Stephen
D3 Wong
D4 Teo

Patient
Patient No Patient Name
P1 William
P2 Lim
P3 Raj
P4 Abdul
P5 Johnson

R2
DoctorNo Patient No Date-of-appointment time SurgeryNo TheatreNumbe
r
D1 P1 19-11-2009 9.00am S1 T1
D1 P2 19-11-2009 10.00am S1 T1
D2 P3 19-11-2009 11.00am S2 T1
D2 P3 26-11-2009 9.00am S5 T1
D3 P2 20-11-2009 11.00am S3 T2
D3 P4 21-11-2009 9.00am S3 T2
D4 P5 21-11-2009 11.00am S4 T2

3NF
Remove Transitive functional dependency:
Doctor-Patient= Appointment-Surgery
Doctor
DoctorNo DoctorName
D1 John
D2 Stephen
D3 Wong
D4 Teo

Patient
Patient No Patient Name
P1 William
P2 Lim
P3 Raj
P4 Abdul
P5 Johnson

Removing the transitive functional dependency available in relation R2 in 2NF


Surgeory -->Theatre

SurgeryNo TheatreNumber
S1 T1
S2 T1
S5 T1
S3 T2
S4 T2

Doctor-Patient- Appointment

DoctorNo Patient No Date-of-appointment time SurgeryNo


D1 P1 19-11-2009 9.00am S1
D1 P2 19-11-2009 10.00am S1
D2 P3 19-11-2009 11.00am S2
D2 P3 26-11-2009 9.00am S5
D3 P2 20-11-2009 11.00am S3
D3 P4 21-11-2009 9.00am S3
D4 P5 21-11-2009 11.00am S4

3NF relations are:

Doctor( DoctorNo, DoctorName)


Patient(PatientNo , PatientName)
Surgery(SurgeryNo, TheatreNumber)
Doctor-Patient- Appointment( DoctorNo, PatientNo, Date-of-appointment, SurgeryNo,
Time)

BCNF: Every determinant is a candidate key


Relation Doctor has one Fd , DoctorNo --> DoctorName and hence one determinant. This
determinant is a candidate key . So it is in BCNF

Relation Patient has one Fd , PartientNo --> PatrientName and hence one determinant. This
determinant is a candidate key . So it is in BCNF

Relation Surgery has one Fd, SurgeryNo--> TheatreNumber and hence one determinant. This
determinant is a candidate key. So it is in BCNF.

Relation Doctor-Patient- Appointment has two Fds


i) ( DoctorNo, PatientNo, Date-of-appointment)

ii) (DoctorNo, PatientNo, SurgeryNo)


There are two determinants and hence two candidate keys.
The two candidate keys are eligible to be the primary keys. Hence this relation is also in
BCNF.

Doctor-Patient- Appointment
DoctorNo Date-of-appointment PatientNo time SurgeryNo
D1 19-11-2009 P1 9.00am S1
D1 19-11-2009 P2 10.00am S1
D2 19-11-2009 P3 11.00am S2
D2 26-11-2009 P3 9.00am S5
D3 20-11-2009 P2 11.00am S3
D3 21-11-2009 P4 9.00am S3
D4 21-11-2009 P5 11.00am S4

Example 2:
The given relation give the Students' grades in different module. One unit leader will be
the in-charge of only one module. Check the normal form of the given relation
Student-Module-Lecture
StudentId ModuleName UnitLeader Grade
S100 CIS Dr. P A
S100 NETWORK Dr.K B
S200 CIS Dr. P A
S300 NETWORK Dr.K C
S400 GRAPHICS Dr. F D
S400 CT Dr. T A
S500 NETWORK Dr.K A
S600 GRAPHICS Dr. F B

Two candidate keys are.


i) (StudentId, ModuleName)
ii) (StudetID, UnitLeader)

The functional dependencies are


Fd1: (StudentId, ModuleName) --> UnitLeader, Grade
Fd2: (StudetID, UnitLeader) --->ModuleName, Grade
Fd3: UnitLeader --> ModuleName

1NF - the relation is in 1NF since there is no repeating group of data.


2NF - the relation is in 2NF since there is no partial functional dependency.
3NF - the relation is in 3NF since there is no transitive functional dependency.

BCNF relations.
There are 3 Fds and hence there are three determinants.
Determinant Fd1 is a candidate key.
Determinant Fd2 is a candidate key.
Determinant Fd3 is NOT a candidate key
Hence this relation is not in BCNF
The BCNF relations are

Student-Module-Lecture
StudentId ModuleName Grade
S100 CIS A
S100 NETWORK B
S200 CIS A
S300 NETWORK C
S400 GRAPHICS D
S400 CT A
S500 NETWORK A
S600 GRAPHICS B

UnitLeader.
UnitLeader ModuleName
Dr. P CIS
Dr.K NETWORK
Dr. F GRAPHICS
Dr. T CT

Example 3:
Consider a following relation which is in BCNF. Check whether the given
relation is in 4NF . If not give the 4NF relations and hence 5NF

4NF - Removing multi-valued dependency.

Student -Hobby

StudentID Game Music

S100 Soccer Saxophone

S100 Soccer Violin

S100 Tennis Violin

S100 Tennis Saxophone

S Basket Ball Piano


200

S200 Basket Ball Guitar

Multi valued- Functional dependency are:


StudentId -->> Game
StudentId -->> Music

4NF relations are.


Student-Game

StudentID Game

S100 Soccer

S100 Tennis

S200 Basket Ball

Student- Music
StudentID Music

S100 Saxophone

S100 Violin

S200 Piano

S200 Guitar

5NF:
Joining Student-Game and Student- Music will give the Student-Hobby
So the 4NF relations Student-Game and Student- Music are in 4NF

Example 4:
Consider a BCNF relation containing Department, Module and Student data as given
below.

DepartmentNo ModuleID StudentID


D10 C2001 S100
D10 C2000 S100
D10 C2003 S200
D12 C2004 S300
D14 C2005 S400
D16 C2006 S500

Department Offers many courses


Courses are taken by students
No subjects are taken by all students.
No students take all the subject.
Therefore, all three attributes are needed to represent the information.

The relation has multi-valued dependencies


DepartmentNo --->>ModuleId
DepartmentNo --->>StudentId

BNCF relation is decomposed into two 4NF relation as given below:

Department-Module
DepartmentNo ModuleID
D10 C2001
D10 C2000
D10 C2003
D12 C2004
D14 C2005
D16 C2006

Department-Student
DepartmentNo StudentID
D10 S100
D10 S200
D12 S300
D14 S400
D16 S500

If the two relations Department-Module and Department-Student are joined


the resulting relation will be

DepartmentNo ModuleID StudentID


D10 C2001 S100
D10 C2001 S200
D10 C2000 S100
D10 C2000 S200
D10 C2003 S200
D12 C2004 S300
D14 C2005 S400
D16 C2006 S500

The records shown in red color are spurious records


( not there in the original records).
So the two relations Department-Module and Department-Student are NOT 5NF.
5NF: Lose-less join
Decompose the relations into three as
1. Department-Module
2. Department-Student
3. Module -Student

Department-Module
DepartmentNo ModuleID
D10 C2001
D10 C2000
D10 C2003
D12 C2004
D14 C2005
D16 C2006

Department-Student
DepartmentNo StudentID
D10 S100
D10 S200
D12 S300
D14 S400
D16 S500

Module -Student
ModuleID StudentID
C2001 S100
C2000 S100
C2003 S200
C2004 S300
C2005 S400
C2006 S500

Natural joining of the three relations gives the original BCNF relations. Hence they are
in 5NF.

Das könnte Ihnen auch gefallen