NoteGPT_Database Normalisation_ Second Normal Form
NoteGPT_Database Normalisation_ Second Normal Form
database to a second normal form it follows on from the video about first normal
form by working through the same example the technical definition of second normal
form states that the data must be in first normal form and a relation must not
contain any partial dependencies what this means is that the data must be in first
normal form and each non key field must be about the same thing as the primary key
also each table must contain data about only one
type of thing this table is in first normal form well debatably let's
remove any argument by separating the first-name and lastname into separate columns
so now the first condition for second normal form is satisfied that is the table is
already in first normal form although it's not necessary for second normal form
let's also clean up the data a little let's give David a last name and let's
suppose there is only one moving Drake after all you can see that there's still an
issue with redundant data here for
every course a student does the students details are duplicated this is a
big clue that the table is not yet in second normal form is that a problem well it
could become one imagine there were thousands of records there'd be even more
duplication and imagine one of the students got married and you wanted to update
their marital status you'd need to make exactly the same change in several places
this is how inconsistency errors can start to creep in let's add some more columns
to exaggerate the problem there's more information about
each course now which means more duplication and there's also the grade
that each student achieved when they completed a course by definition to be in
second normal form a relation in other a table must not have any attributes that
are partially dependent on the primary key a much simpler way of saying that is a
table should only contain data about one type of thing or to be slightly more
technical a table should only contain data about one type of entity if it's about
more than one type of entity the data need to be split into
separate tables so what's this table about what things does it describe
for a start it contains various data which are just about students an ID first name
last name and marital status when you examine the data you can see that the ID is
unique for each student and that the first name last name and marital status are
each about the same thing that the ID is about this table uses a simple sequential
number for each ID but it could have used something more personal like a Student
Union number or a
contains various data just about courses the course title fee and
qualification examine the data and you can see that the course title is unique for
each course the fee and qualification are both about the same thing as the course
title change the course title for a course and it becomes a different course so you
need to change the fee and the qualification as well they are functionally
dependent on the course title and it's the only thing that they function be
dependent on and finally and this
might not be immediately obvious this table also contains data about each
student and course combination look at the grade column each student has a grade
for each course they attended Kevin drum for example did three courses so he has
three separate grades each of Kevin's grades is not just about Kevin it's also
about the course he did to achieve that grade each grade is partially dependent on
the student and partially dependent on the course now consider this tables primary
key for a moment at first sight it might not
appear to have a primary key at all the ID column is unique for each
student but it's not unique for each record so by definition the ID column is not
the primary key of this table the course title column is unique for each course but
it's not unique for each record so it can't be the primary key of this table
however the combination of ID and course title is unique for each record together
these two fields serve as a composite primary key the primary key for each record
in this table contains a
is functionally dependent on the primary key and only the primary key
there are no partial dependencies the student course table is about which students
enrolled on which courses and how well each student performed it only contains
information about each student course combination the combination of ID and course
title is unique in the student course table so this table has a composite primary
key every non-key attributes in this table namely the grade is about the student
course combination the grade is functionally
dependent on the primary key and only the primary key there are no
partial dependencies here all of these tables are now in second normal form the
student course table is sometimes called a bridging table or a linked entity
because it serves to join the three tables together overall there are fewer
individual data items being stored than when there was a single table in first
normal form the database is now more space efficient and this efficiency will
become even more significant as the number of students and courses grows not
each table must contain data about only one type of thing only one type
of entity you can see how important it is to know what the data means in order to
make these decisions