Download presentation
Presentation is loading. Please wait.
Published byRalf Chambers Modified over 9 years ago
1
The Teacher Computing Database Design CP4 Revision
2
The Teacher Computing Database Design Careful database design is needed to avoid… Data Redundancy – storing the same data item in more than one place (waste of storage space) Data Inconsistency – two versions of the same data may be different.
3
The Teacher Computing Entities An entity is a thing about which data is stored (Eg Customer, Employee, Stock) A relationship is a link between two entities.
4
The Teacher Computing Relationships One-to-One : One Pupil has one Network Account. One-to-Many : One Pupil borrows many LibraryBooks Many-to-Many : One Teacher teaches many Pupils – One Pupil is taught by many Teachers.
5
The Teacher Computing Entity-Relationship Diagrams One-to-One One-to-Many Many-to-Many
6
The Teacher Computing Key Fields Each Entity must have a unique key field – the primary key. An Entity may have foreign keys – primary key fields of other entities. These provide the links (relationships) between different entities. WardID is a foreign key. PatientIDSurnameForenameDiseaseWardID P101SmithPaulMeaslesW10 P102JonesJaneMumpsW12 P103WilkinsMaryMeaslesW10 P104JacksonTomTonsillitisW17 PatientID is the primary key field.
7
The Teacher Computing Table Design The standard notation for writing down the design of a table… CAPITAL letters for the name of the table Underline the key field, Italicise the foreign keys. Eg.: PATIENTS (PatientID, Surname, Forename, Disease, WardID)
8
The Teacher Computing Database Normalisation Avoids data duplication Avoids data inconsistencies …ensures the best possible design for a database so other applications can use it.
9
The Teacher Computing Un-Normalised Data PupilIDPupilNameDOBExamIDSubjectLevelDateRoomIDRoomName P99010Jane Grey12.03.86CP101 EN004 AR075 Computing English Art AS GCSE AS 15.05.01 24.05.01 12.06.01 UH UG Hall Gym P99205Tom Jones05.11.86CP101 MA110 PH190 Computing Maths Physics AS 15.05.01 15.06.01 08.06.01 UH UG 58 Hall Gym Science Lab P99311Sam Hill16.08.86CP101 EN004 Computing English AS GCSE 15.05.01 24.05.01 UH UG Hall Gym There are a number of repeated fields here… To change into First Normal Form – the repeated groups of fields must go… Split into two linked tables…
10
The Teacher Computing First Normal Form PUPILS ( PupilID, PupilName, DOB, ExamID) EXAMS ( ExamID, Subject, Level, Date, RoomID, RoomName) The key field of the PUPILS table is a combined key field. The link is made through the foreign key ‘ExamID’. PupilIDPupilNameDOBExamID P99010Jane Grey12.03.86CP101 P99010Jane Grey12.03.86EN004 P99010Jane Grey12.03.86AR075 P99205Tom Jones05.11.86CP101 P99205Tom Jones05.11.86MA110 P99205Tom Jones05.11.86PH190 P99311Sam Hill16.08.86CP101 P99311Sam Hill16.08.86EN004 ExamIDSubjectLevelDateRoomIDRoomName CP101ComputingAS15.05.01UHHall AR075ArtAS12.06.01UGGym MA110MathsAS15.06.01UGGym PH190PhysicsAS08.06.0158Science Lab EN004EnglishGCSE24.05.01UGGym To get this into Second Normal Form, no field must be dependant on only part of the key field. Do this by creating a linking table HINT : You need to do this every time you have a Many-to-Many relationship)
11
The Teacher Computing Second Normal Form PUPILS ( PupilID, PupilName, DOB) EXAMS ( ExamID, Subject, Level, Date, RoomID, RoomName) PUPIL_SITS(PupilID,ExamID) …must be changed to… The Many-to-Many relationship…
12
The Teacher Computing Second Normal Form PupilIDPupilNameDOB P99010Jane Grey12.03.86 P99205Tom Jones05.11.86 P99311Sam Hill16.08.86 ExamIDSubjectLevelDateRoomIDRoomName CP101ComputingAS15.05.01UHHall AR075ArtAS12.06.01UGGym MA110MathsAS15.06.01UGGym PH190PhysicsAS08.06.0158Science Lab EN004EnglishGCSE24.05.01UGGym PupilIDExamID P99010CP101 P99010EN004 P99010AR075 P99205CP101 P99205MA110 P99205PH190 P99311CP101 P99311EN004 To make this database into Third Normal Form, there must be no non-key dependencies…..so separate the Rooms into another table…
13
The Teacher Computing Third Normal Form PupilIDPupilNameDOB P99010Jane Grey12.03.86 P99205Tom Jones05.11.86 P99311Sam Hill16.08.86 PupilIDExamID P99010CP101 P99010EN004 P99010AR075 P99205CP101 P99205MA110 P99205PH190 P99311CP101 P99311EN004 ExamIDSubjectLevelDateRoomID CP101ComputingAS15.05.01UH AR075ArtAS12.06.01UG MA110MathsAS15.06.01UG PH190PhysicsAS08.06.0158 EN004EnglishGCSE24.05.01UG RoomIDRoomName UHHall UGGym UGGym 58Science Lab UGGym PUPILS (PupilID, PupilName, DOB) EXAMS (ExamID, Subject, Level, Date, RoomID) PUPIL_SITS (PupilID, ExamID) ROOMS (RoomID, RoomName)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.