School DatabaseStudent ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher NumberS10204 HALL Taighan 10B F 13 Maths101 PRJ 651S10204 HALL Taighan 10B M 13 GEO101 RW 532S10204 HALL Taighan 10B F 13 SCI10 CW 161S10412 CRIST Graeme 10D M 14 GEO101 RW 532S10412 CRIST Graeme 10D M 14 HIS101 HJD 541S10101 CRIST Graeme 10D M 14 Maths101 PRJ 651S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651S10101 FUNG JUNE 10B F 15 GEO101 HJD 532S10101 FUNF JUNE 10A F 15 HIS101 HJD 541 This is part of a database showing all students and their classes in a school.
Data integrity and Data RedundancyThese issues can have a significant impact on the ability for a database to actuallydo the job that it is intended to do.Data Integrity is the idea that information always keeps its meaning. This isparticularly difficult when database get really big if you imagine if the databaseabove includes every student and every class in the school it could contain over10000 records.
Examples of Data integrityExamples of Data integrity A simple typo means that it might mean that information gets lost if we search forJune in the data. This problem is much more likely because of the redundanciesissues we will look at later. This example can cause real problems it shows that the same information in thedatabase can mean two different things is s10101 Graeme or June. What happen iss10101 Here we have June in two classes? Which one is right? What if we need to fineJune in registration urgently
Hard to find?They can be really hard to find in this Database there are more integrity errors canyou find them?
Bad or unnecessary Fields NamesAge is an example of a bad field name for the obvious reason that it can change atanytime. It would be much better to use DOB as age can always be calculated andof course it does not change.Form may also be unnecessary in this case as the reference number is CODED togive the form.Can you explain the code?
School DatabaseStudent ID Student Student Form Sex Age Class Class Room Surname FirstName Name Teacher NumberS10204 HALL Taighan 10B F 13 Maths101 PRJ 651S10204 HALL Taighan 10B M 13 GEO101 RW 532S10204 HALL Taighan 10B F 13 SCI10 CW 161S10412 CRIST Graeme 10D M 14 GEO101 RW 532S10412 CRIST Graeme 10D M 14 HIS101 HJD 541S10101 CRIST Graeme 10D M 14 Maths101 PRJ 651S10414 HASLETT Oliver 10D M 14 Maths101 PRJ 651S10101 FUNG JUNE 10A F 15 Maths101 PRJ 651S10101 FUNG JUNE 10B F 15 GEO101 HJD 532S10101 FUNF JUNE 10A F 15 HIS101 HJD 541 Table showing data redundancy .
Data RedundancyData redundancy is the where data needs to be entered and stored on morethan one occasion.For example if you look at the table above you can see that we have enteredOliver Haslett’s first name and surname every time we put him into a class.This can cause problems such as increasing the chance of someone enteringhis name wrong. It also means more time is needed to enter data and morespace is needed when it is saved.There is a way around this …………
Relational DatabasesThe simple way to think about this is that when you create a table of data in adatabase you should have fields which directly relate to the key field of the table.In our table we can see that the Class teacher, Class Name and Room Number arenot related to the Student. The Student ID is unique so the first name, surname,form, Sex is all related to the student but the other fields do not.We can now look at how to remove redundancy issues a process callednormalization, although this can be very complex and we are only going to look itis a simple way.Student Student Student First Form Sex Age Class Name Class Teacher RoomID Surname NumberS10204 HALL Taighan 10B F 13 Maths101 PRJ 651S10204 HALL Taighan 10B M 13 GEO101 RW 532S10204 HALL Taighan 10B F 13 SCI10 CW 161
Removing Redundancy (“Normalization”)If we create these tables we remove the redundancy but there is a problem.Why? CLASS STUDENT ClassID StudentID Class Name Student First Name Class Teacher Student Surname Room Number Student DOB Student Form These tables have what is called a many to many relationship. That is there are many students in each class and there are many class for each student. This kind of relationship will not work in a database.
Step 2To solve this problem we create an extra table which contains the StudentID andClassID for each student in each class.What this does is remove the many to much relationship and replace it witha one to many or many to one relationship.That one student can be in many classes and one class has many students.We can use the relationships to find the information we need in each case makinguse of something called Queries that we will look at later.
How it looksSTUDENT CLASSStudentID ClassIDFirstName Class NameSurname Class TeacherDOB Room NumberForm STUDENTTAKES StudentID ClassID This goes a long way to solving our problem but there remains a potential problem with the room number field which could give use problems in what we want to do with the data. Why ?
STEP 3 (optional?)Room number is not actually related to the class. What happens if a class is inmore than one room for example? If you were to do the normalization properlyyou would need to remove room Number and potentially create another tableRooms as shown below. This is called an Entity Relationship Diagram and they areused to show the data structure in a database.This stage can sometimes be a really difficult to do as you really need tounderstand what the data is going to be used for to see if it needs to be done. Student StudentTakes Class RoomClass Room
Try it for your selfLet’s imagine you want to keep a database of films and actors in those films. Using thelist of fields below can you create the table structure which would allow findinformation about films and the actors in them?Film Film date Film Film Genre Actor First Actor Actor Director ActorTitle Description Name Surname DOB SexTitanic 1997 Film about a Romance Kate Winslet 1975 James F sinking ship CameroonTitanic 1997 Film about a Romance Leonardo Di Caprio 1974 James M sinking ship CameroonStar 1977 Film about Space Mark Hamill 1951 George Lucas MWars spaceStar 1977 Film about Space Harrison Ford 1942 George Lucas MWars space