Professional Documents
Culture Documents
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.
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.
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.
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.
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
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
SurgeryNo TheatreNumber
S1 T1
S2 T1
S5 T1
S3 T2
S4 T2
Doctor-Patient- Appointment
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.
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
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
Student -Hobby
StudentID Game
S100 Soccer
S100 Tennis
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.
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
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.