Flat file and relational databases 3.3.9
Flat file database In a flat file database information is held in a single table. Student IDStudent name GenderDOBCourse IDCourse nameTeacher IDTeacher name 67678Jim SmithM30/01/20F451Computer fundamentals 4445Mr Surrall 67677Jane JonesF02/01/20F451Computer fundamentals 4445Mr Surrall 67678Jim SmithM30/01/20F452Programming & logic 4433Mr Surrall 67222Lucy KidF08/03/20F452Programming & logic 4445Mr Surrall
Flat file databases This presents three main problems: ● Lots of data is duplicated wasting memory. ● The same changes need to be made in lots of places if data needs updating. ● Very inefficient if you want to add new data ie a teachers address
Relational databases Relational databases were created to remove the problems with flat file databases. Relational databases are made up of lots of smaller tables linked together using Primary & Foreign keys.
Studen t ID Studen t name GenderDOBCourse numbe r 67678Jim Smith M30/01/ 20 F Jane Jones F02/01/ 20 F Jim Smith M30/01/ 20 F Lucy Kid F08/03/ 20 F452 Course IDCourse name Teacher ID Teacher name F451Computer fundament als 4445Mr Surrall F452Programmi ng & logic 4445Mr Surrall The Primary Key is a unique identifier. The Foreign key is the field that links to the Primary key in another table Students Course
Normalisation The process of converting a flat file database into a relational one is called normalisation. There are three stages in this normalisation called normal forms.
First normal form (1NF) A table is in first normal form if it contains no repeating attributes or groups of attributes.
Studen t ID Studen t name GenderDOBCourse numbe r 67678Jim Smith M30/01/ 20 F Jane Jones F02/01/ 20 F Jim Smith M30/01/ 20 F Lucy Kid F08/03/ 20 F452 Course IDCourse name Teacher ID F451Computer fundament als 4445 F452Programmi ng & logic 4445 Teacher ID Teacher name 4445Mr Surrall Students CourseTeacher
Second normal form (2NF) A table is in second normal form if it is in first normal form and no column which is not part of the primary key is dependant on only a portion of the primary key.
Studen t ID Studen t name GenderDOB 67678Jim Smith M30/01/ Jane Jones F02/01/ Lucy Kid F08/03/ 20 Course IDCourse name Teacher ID F451Computer fundament als 4445 F452Programmi ng & logic 4445 Teacher ID Teacher name 4445Mr Surrall Student ID Course number 67678F F F F452 StudentsEnrollment Course Teacher
Third normal form A table is in third normal form if it is in second normal form and contains no column that is not directly related to the primary key. A table is in third normal form if it contains no ‘non-key dependencies’
Studen t ID Studen t name GenderDOB 67678Jim Smith M30/01/ Jane Jones F02/01/ Lucy Kid F08/03/ 20 Course IDCourse name F451Computer fundament als F452Programmi ng & logic Teacher ID Teacher name 4445Mr Surrall Student ID Course number 67678F F F F452 Course ID Teacher ID F F StudentsEnrollment CourseStaff Teacher