Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Transforming the Data Model into Relations (Tables) and Normalisation Students.

Similar presentations


Presentation on theme: "1 Transforming the Data Model into Relations (Tables) and Normalisation Students."— Presentation transcript:

1 1 Transforming the Data Model into Relations (Tables) and Normalisation Students

2 2 External Level Specification - Identify all User views zUser View - subset of data required by user. Takes the form of zprinted report-e.g. register zscreen display - e.g.. all student info.. zinput form zroutine query - e.g. how many students on course? zad hoc query - e.g. which courses does F.Bloggs take

3 3 zDraw an ER diagram of each user view integrate to produce ER diagram of system (each entity with attributes to appear only once) zThis should ensure that all the attributes have been included

4 4 Transforming the data model into Tables (relations) zeach entity becomes a table with a column for each attribute, the entity identifier is the primary key for the table. z1:N relationship is represented by placing the primary key on one side of the relationship, as a foreign key in the table for the entity in the many side

5 5 e.g. customer : order (a one to many relationship) cust-no.nameaddresscitydiscount order-no. order-datepromised-datecust-no. CUSTOMER TABLE primary key foreign key one Many ORDER TABLE

6 6 An M:N (Many to Many) relationship zTo avoid an invalid construct, create a new table to represent the relationship, the primary key for this is a composite key comprising of the primary keys of the entities on either side of the relationship. e.g. ORDER PRODUCT QUANTITY ORDERED REQUESTED ON

7 7 M:N relationship example (contd) ORDER TABLE Order-No.Order-date..... PRODUCT TABLE Product-No.Description...... ORDER-LINES Order-No.Product-No.Quantity primary key Composite Primary Key

8 8 Class and Sub Class zcreate separate tables for the class and each sub class zthe class table contains only attributes that are common to all subclasses plus a sub class definition column zthe sub class table contains the primary key and only attributes common to that sub class zthe primary keys for the class and subclass tables are the same

9 9 STUDENT Reg-No. NameU/Grad P/Grad address Reg-No.Year of StudyCourse UNDERGRADUATE Reg-No.Program POSTGRADUATE sub class definition Primary Keys Class / Sub class example

10 10 Students Example used for next section on Normalisation Students Student_ID Student_Name Campus_Address Core_Subject Tutor Tutor_Name Tutor_Room Course Course_ID Course_Title Tutor_Name Registration Student_ID Course_ID Exam_Grade Register on teaches on Taken on by

11 11 Normalisation zThe process of decomposing complex data structures into simple relations according to a set of dependency rules. zA step-by-step process used to decompose complex data structures into simple entities (Dowling)

12 12 Normalisation zOrganising data into tables (files) to minimise data repetition e.g. Redundancy -course fee repeated Insertion - A new course cannot be added until a student registers Deletion - if student 12347 withdrew from course we would loose BUS fee information Updating - If MBA fee changed we would have to alter records of all MBA students

13 13 Normalised zNormalising the data gives Now easy to insert or delete students/course also update fees requires only one amendment BUT may take longer to execute queries

14 14 The First Normal Form (1NF) (refer to handout) n 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

15 15

16 16 zCreate three new relations (tables) from the first normal form (1NF) zOrganise the attributes into tables, the table key value directly or indirectly determines attribute values y e.g. Student, Course_Tutor and Exam_Result zThis results in 2NF relations (or tables) as shown (N.B two of the relations are already in third normal form) Second Normal Form (2NF)

17 17 2NF (contd) zThe table Course_Tutor is still in 2NF because it is still open to the problems discussed earlier i.e. zinsertion problems ; its difficult to add a new tutor zupdate problems ; Tutor_Location must be changed a number of times zdeletion 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

18 18 Course Tutor Course_Tutor Third Normal Form Second Normal Form

19 19 Third Normal Form (3NF ) zthe removal of transient dependencies results in the third normal form (3NF) zdivide Course_Tutor into two tables as shown zTutor_Name becomes a foreign key zi.e. an attribute which is a non-key in one table (like Course) and a primary key in another table (like Tutor) zthe foreign key is indicated by underlining with a dashed line zThe normalisation process is now complete


Download ppt "1 Transforming the Data Model into Relations (Tables) and Normalisation Students."

Similar presentations


Ads by Google