Transforming the Data Model into Relations (Tables) and Normalisation Students 1 External Level Specification - Identify all User views User View - subset of data required by user. Takes the form of printed report-e.g. register screen display - e.g.. all student info.. input form routine query - e.g. how many students on course? ad hoc query - e.g. which courses does F.Bloggs take 2 Draw an ER diagram of each user view integrate to produce ER diagram of system (each entity with attributes to appear only once) This should ensure that all the attributes have been included 3
Transforming the data model into Tables (relations) each entity becomes a table with a column for each attribute, the entity identifier is the for the table. 1:N relationship is represented by placing the on one side of the relationship, as a foreign key in the table for the entity in the many side 4 e.g. customer : order (a one to many relationship) CUSTOMER TABLE cust-no. name address city ORDER TABLE discount one order-no. order-date promised-date cust-no. Many foreign key 5 An M:N (Many to Many) relationship To avoid an invalid construct, create a new table to represent the relationship, the for this is a composite key comprising of the s of the entities on either side of the relationship. e.g. ORDER REQUESTED ON PRODUCT QUANTITY ORDERED 6
M:N relationship example (contd) ORDER TABLE Order-No. Order-date... PRODUCT TABLE Product-No. Description... ORDER-LINES Order-No. Product-No. Quantity Composite Primary Key 7 Class and Sub Class create separate tables for the class and each sub class the class table contains only attributes that are common to all subclasses plus a sub class definition column the sub class table contains the and only attributes common to that sub class the s for the class and subclass tables are the same 8 Class / Sub class example sub class definition STUDENT Reg-No. Name U/Grad P/Grad address UNDERGRADUATE Reg-No. Year of Study Course Primary Keys POSTGRADUATE Reg-No. Program 9
Students Example used for next section on Normalisation Registration Student_ID Course_ID Exam_Grade Taken on by Course Course_ID Course_Title Tutor_Name Register on Students Student_ID Student_Name Campus_Address Core_Subject teaches on Tutor Tutor_Name Tutor_Room 10 Normalisation The process of decomposing complex data structures into simple relations according to a set of dependency rules. A step-by-step process used to decompose complex data structures into simple entities (Dowling) 11 Normalisation Organising data into tables (files) to minimise data repetition e.g. Deletion - if student 12347 withdrew from course we would loose BUS fee information Student- Course Fee Reg-No. 12345 ISM 4000 12346 MBA 3500 12347 BUS 4200 12348 ISM 4000 12349 MBA 3500 Insertion - A new course cannot be added until a student registers Redundancy -course fee repeated Updating - If MBA fee changed we would have to alter records of all MBA students 12
Normalised Normalising the data gives Student Course Reg.No. 12346 MBA 12345 IS M 12347 BUS Course Fee MBA 3500 IS M 4000 BUS 4200 Now easy to insert or delete students/course also update fees requires only one amendment BUT may take longer to execute queries 13 The First Normal Form (1NF) (refer to handout) Analyse functional dependencies i.e. the relationship between two attributes Student-ID -> Student_Name, Campus_Address, Core_Subject Course-ID -> Course_Title, Tutor_Name, Tutor_Location Student-ID,Course-ID -> Exam_Grade i.e sort out which attributes uniquely depend on other attributes. the independent attribute becomes the key for the 2NF tables. e.g. Student_ID and Course_ID 14 Student_ID Student_Name Campus_Address Core_Subject Course_ID Course_Title Tutor_Name Tutor_Room Exam_Grade 268300458 Munro 213 Ash ISM ISO6 Relational Databases Baxter 3X9 B ISO3 Java Programming Marshall 4A126 A 543291073 Jackson 432 Spruce QM QM2 Total Quality Management Bentley 3A54 D QM1 Quality Function Deployment Kanji 4B98 C QM7 Quality standards Seddon 3A67 A Unnormalised Student_ID Student_Name Campus_Address Core_Subject Course_ID Course_Title Tutor_Name Tutor_Room Exam_Grade 268300458 Munro 213 Ash ISM ISO6 Relational Databases Baxter 3X9 B 268300458 Munro 213 Ash ISM ISO3 Java Programming Marshall 4A126 A 543291073 Jackson 432 Spruce QM QM2 Total Quality Management Bentley 3A54 D 543291073 Jackson 432 Spruce QM QM1 Quality Function Deployment Kanji 4B98 C 543291073 Jackson 432 Spruce QM QM7 Quality standards Seddon 3A67 A Normalised (1NF) COURSE_DETAILS Course_ID Course_Title Tutor_Name ISO6 Relational Databases Baxter COURSE_TUTOR Course_ID Course_Title Tutor_Name Tutor_Room ISO3 Java Programming Marshall ISO6 Relational DatabaseBaxter 3X9 QM2 Total Quality Management Bentley ISO3 Java Programming Marshall 4A126 QM1 Quality Function Deployment Kanji QM2 Total Quality ManagBentley 3A54 QM7 Quality standards Seddon COURSE_TUTOR splits into QM1 Quality Function De Kanji 4B98 3rd Normal Form (3NF) QM7 Quality standards Seddon 3A67 2nd Normal Form (2NF) TUTOR_DETAILS Tutor_Name Tutor_Room Baxter 3X9 Marshall 4A126 Bentley 3A54 REGISTRATION Student_ID Course_ID Exam_Grade Kanji 4B98 268300458 ISO6 B Seddon 3A67 268300458 ISO3 A 3rd Normal Form (3NF) 543291073 QM2 D 543291073 QM1 C 543291073 QM7 A 3rd Normal Form (3NF) STUDENT Student_ID Student_Name Campus_Address Core_Subject 268300458 Munro 213 Ash ISM 543291073 Jackson 432 Spruce QM 3rd Normal Form (3NF) 15
Second Normal Form (2NF) Create three new relations (tables) from the first normal form (1NF) Organise the attributes into tables, the table key value directly or indirectly determines attribute values e.g. Student, Course_Tutor and Exam_Result This results in 2NF relations (or tables) as shown (N.B two of the relations are already in third normal form) 16 2NF (contd) The table Course_Tutor is still in 2NF because it is still open to the problems discussed earlier i.e. insertion problems ; its difficult to add a new tutor update problems ; Tutor_Location must be changed a number of times deletion problems ; if we delete course QM2 from the table (and it is the only row) we may lose the information that instructor Bentley is located in 3A54 17 Course_Tutor Course_ID Course_Title Tutor_Name Tutor_Room ISO6 Relational Databases Baxter 3X9 ISO3 Java Programming Marshall 4A126 QM2 Total Quality Management Bentley 3A54 QM1 Quality Function Deployment Kanji 4B98 QM7 Quality standards Seddon 3A67 Second Normal Form Course Course_ID Course_Title Tutor_Name ISO6 Relational Databases Baxter ISO3 Java Programming Marshall QM2 Total Quality Management Bentley QM1 Quality Function Deployment Kanji QM7 Quality standards Seddon Third Normal Form Tutor Tutor_Name Tutor_Room Baxter 3X9 Marshall 4A126 Bentley 3A54 Kanji 4B98 Seddon 3A67 Third Normal Form 18
Third Normal Form (3NF) the removal of transient dependencies results in the third normal form (3NF) divide Course_Tutor into two tables as shown Tutor_Name becomes a foreign key i.e. an attribute which is a non-key in one table (like Course) and a primary key in another table (like Tutor) the foreign key is indicated by underlining with a dashed line The normalisation process is now complete 19