Chapter 56 Relational Database Design Compiled by Eddie Moorcroft.

Slides:



Advertisements
Similar presentations
BUSINESS DRIVEN TECHNOLOGY Plug-In T4 Designing Database Applications.
Advertisements

RJP/RDA 1 /93 Relational Data Analysis (RDA) RDA organises all the system’s data items into a set of well NORMALISED relations. These should avoid: 1.
WJEC Applied ICT Databases – Attributes & Entities Normalisation It is important in Database Design to make sure that the correct attributes are grouped.
GCSE Computing#BristolMet Session Objectives# 21 MUST describe methods of validating data as it is input. SHOULD explain the use of key fields to connect.
Normalisation Ensuring data integrity in database design 1.
Athabasca University Under Development for COMP 200 Gary Novokowsky
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
The Relational Database Model:
Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.
1 NORMALISATION. 2 Introduction Overview Objectives Intro. to Subject Why we normalise 1, 2 & 3 NF Normalisation Process Example Summary.
Project and Data Management Software
Relational Databases What is a relational database? What would we use one for? What do they look like? How can we describe them? How can you create one?
Databases Tom Morgan.
Copyright © 2016 McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
File and Database Design SYS364. Today’s Agenda WHTSA DBMS, RDBMS, SQL A place for everything and everything in its place. Entity Relationship Diagrams.
2.3 Organising Data for Effective Retrieval
Module Title? DBMS E-R Model to Relational Model.
Week 6 Lecture Normalization
The Teacher Computing Database Design CP4 Revision.
DATA MODELLING TOOLS FOR ORGANISING DATABASES. For a database to be organised and logical, it must be well-designed and set out. In such cases, the databases.
WJEC Applied ICT Databases – Terminology and Notation DEFINITION A database is a collection of data or information which is held together in an organised.
CREATE THE DIFFERENCE Normalisation (special thanks to Janet Francis for this presentation)
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Concepts and Terminology Introduction to Database.
Relational databases and third normal form As always click on speaker notes under view when executing to get more information!
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
Normalization A technique that organizes data attributes (or fields) such that they are grouped to form stable, flexible and adaptive entities.
Normalisation Mia’s Sandwich Shop The Process Explained.
Database Normalization Lynne Weldon July 17, 2000.
In this chapter, you learn about the following: ❑ Anomalies ❑ Dependency and determinants ❑ Normalization ❑ A layman’s method of understanding normalization.
CORE 2: Information systems and Databases NORMALISING DATABASES.
MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta.
Chapter 55 Data Modelling - Introduction Compiled by Eddie Moorcroft Source: P M Heathcote A level ICT.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T5 DESIGNING DATABASE APPLICATIONS.
Normalization Information Systems II Ioan Despi. Informal approach Building a database structure : A process of examining the data which is useful & necessary.
1 Information Retrieval and Use Data Analysis & Data Modeling, Relational Data Analysis and Logical Data Modeling Geoff Leese September 2009.
What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them.
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
Database Beginnings. Scenario so far In our scenario we have people registering for training sessions. –The data about the training sessions was placed.
Introduction to Database using Microsoft Access 2013 Part 7 November 19, 2014.
M1G Introduction to Database Development 4. Improving the database design.
Entity-Relationship (E-R) Diagrams
+ Information Systems and Databases 2.2 Organisation.
Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used.
A337 - Reed Smith1 Structure What is a database? –Table of information Rows are referred to as records Columns are referred to as fields Record identifier.
+ Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have.
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
Flat Files Relational Databases
Sample Table Standard Notation Entity name in uppercase
Information Systems Database Systems (H).
Microsoft Access 2010 Chapter 11 Database Design.
Databases Database Normalisation. Learning Objectives Design simple relational databases to the third normal form (3NF).
NormalisationNormalisation Normalization is the technique of organizing data elements into records. Normalization is the technique of organizing data elements.
IMS 4212: Normalization 1 Dr. Lawrence West, Management Dept., University of Central Florida Normalization—Topics Functional Dependency.
Teanna Clarke 6aQ What is a Entity-Relationship Diagram?  An Entity-Relationship Diagram (ERD) is a tool that graphically shows the connections among.
MS Access. Most A2 projects use MS Access Has sufficient depth to support a significant project. Relational Databases. Fairly easy to develop a good user.
Normalisation Unit 6: Databases. Just to recap  What is an Entity  What is an Attribute?
Starter Draw a mind map for topic 6 Databases. Objectives Revise topic CG3.6 Databases using various activities and ensure that topics covered are understood.
Year 12 > 13 Applied GCE ICT Unit 7 Using Database Software.
Normalisation FORM RULES 1NF 2NF 3NF. What is normalisation of data? The process of Normalisation organises your database to: Reduce or minimise redundant.
NORMALISATION OF DATABASES. WHAT IS NORMALISATION? Normalisation is used because Databases need to avoid have redundant data, which makes it inefficient.
Flat file and relational databases Flat file database In a flat file database information is held in a single table. Student IDStudent name GenderDOBCourse.
Databases – Exam questions
Normalization and Databases
Database Normalisation
Spreadsheets, Modelling & Databases
BTEC ICT – Unit 18 With Mr Griffiths.
Presentation transcript:

Chapter 56 Relational Database Design Compiled by Eddie Moorcroft

Chapter 56 - ICT5 The Basics A relational database is a widely-used type of DBMS (Database Management System) Data is held in tables The relationships are in fact links between common fields in different tables. One row of a table holds one record. Each column in a table holds one field or attribute.

Chapter 56 - ICT5 Typical table IMPORTANT Standard Notation BOOK(AccessionNo, DeweyCode, Title, Author,DatePublished) Entity name in uppercase Key field (unique identifier) is underlined All attributes are shown in brackets, separated by commas N.B A PRIMARY key uniquely references each record SIMPLE key is based on one attribute (field) COMPOSITE key is based on two or more attributes (fields) Accession Number DeweyCodeTitleAuthorDate Published Let’s CookChan, C ElectricityGlendenning, V RidersCooper, J Greek in 3 weeksStavros, G1990 etc…

Chapter 56 - ICT5 Linking database tables Tables are linked through the use of a common field. This field must be a key field in another table. It is known as a foreign key. Consider this library database relationship:  One possible model in standard database notation BORROWER(BorrowerID, Name, Address) BOOK(AccessionNo, DeweyCode, Title, Author, DatePublished, BorrowerID, DateDue) Consider possible flaws in this model and suggest a better one. BORROWERBOOK borrows

Chapter 56 - ICT5 Normalisation Normalisation is a process used to come up with the best possible design for a relational database. Tables should be organised in such a way that: 1. No data is unnecessarily duplicated 2. Data is consistent throughout the database 3. The structure of each table is flexible enough to allow you to enter as many or as few items as you want to 4. The structure should enable a user to make all kinds of complex queries relating data from different tables

Chapter 56 - ICT5 First normal form Definition: A table is in first normal form if it contains no repeating attributes or groups of attributes. i.e. if data is repeated, then it should be held in another table, with a relationship – see example following.

Chapter 56 - ICT5 Consider the following un-normalised data. STUDENT (Admission number, Surname, Forename, Title, Address, Telephone no., Gender, Date of birth, Course code, Course Title, Level of course, Date joined, Date left, Lecturer number, Lecturer name, Room number ) We see that information about each course is repeated for each student. So use the model of two entities STUDENT and COURSE. STUDENT (Admission number, Surname, Forename, Title, Address, Telephone no., Gender, Date of birth, Course code ) COURSE (Course Code, Course Title, Level of course, Date joined, Date left, Lecturer number, Lecturer name, Room number ) A student can take several courses, and each course has several students attending. The relationship can be represented by the entity-relationship diagram: First normal form STUDENTCOURSE attends

Chapter 56 - ICT5 Sample data to be held in a database It is always useful to view a sample of the un-normalised data, as above. Often, it is worthwhile to put this data in an Excel spreadsheet, and reorder it by different fields, to see if data is repeating. Student number Student name Date of birth SexCourse number Course nameLecturer number Lecturer name 12345Jones, P20/05/1984MITA201A Level ICTT345267Moorcroft, E 22433Phillips, K16/02/1983FITA201A Level ICTT345267Moorcroft, E 22433Phillips, K16/02/1983FMUA201A Level MusicT773351Parry, D 22433Phillips, K16/02/1983FSPA201A Level SpanishT876541n/a 66688Smith, J25/12/1984MMDA201A Level MathsT666758Newton, I 66688Smith, J25/12/1984MMUA201A Level MusicT773351Parry, D etc

Chapter 56 - ICT5 In the previous example, the data should be split into two tables, STUDENT and COURSE, in standard database notation: STUDENT(StudentNumber, StudentName, DateOfBirth,Sex) COURSE(CourseNumber,CourseName,LecturerNumber, LecturerName) Consider the problems of creating a relationship between these two tables. Remember a link has to made between common fields Course number Course nameLecturer number Lecturer name ITA201A Level ICTT345267Moorcroft, E MDA201A Level MathsT666758Newton, I MUA201A Level MusicT773351Parry, D SPA201A Level Spanish T876541n/a etc Student number Student name Date of birthSex 12345Jones, P20/05/1984M 22433Phillips, K16/02/1983F 66688Smith, J25/12/1984M etc

Chapter 56 - ICT5 Creating the relationship We need a common field, but the problem is that because this is a many-to-many relationship, whichever table we put the link field into, there needs to be more than one field. e.g. STUDENT (student number, student name, date of birth, sex, course number ) is no good because the student is doing several courses, so which one would be mentioned? Similarly, COURSE (course number, course name, lecturer number, lecturer name, student number ) is no good either because each course has a number of students taking it. How about allowing space for 3 courses on each student record? STUDENT (student number, student name, date of birth, sex, course1, course2, course3 ) Why is this not a good idea?

Chapter 56 - ICT5 Creating the relationship What we have engineered is a repeating attribute – unacceptable in 1st normal form. In other words, the field course number is repeated 3 times The table is therefore NOT in first normal form. It would be represented in standard notation with a line over the repeating attribute: STUDENT (student number, student name, date of birth, sex, course number) To put the data into first normal form, the repeating attribute must be removed.

Chapter 56 - ICT5 Creating the relationship In its place, the field course number becomes part of the primary key in the student table. The tables are now as follows: STUDENT (student number, student name, date of birth, sex, course number) COURSE (course number, course name, lecturer number, lecturer name) Discussion: What is a primary key? Why does course number have to be part of the primary key?

Chapter 56 - ICT5 The situation so far: Student numberStudent nameDate of birthSexCourse number 12345Jones, P20/05/1984MITA Phillips, K16/02/1983FITA Phillips, K16/02/1983FMUA Phillips, K16/02/1983FSPA Smith, J25/12/1984MMDA Smith, J25/12/1984MMUA201 etc Course numberCourse nameLecturer numberLecturer name ITA201A Level ICTT345267Moorcroft, E MDA201A Level MathsT666758Newton, I MUA201A Level MusicT773351Parry, D SPA201A Level SpanishT876541n/a etc STUDENT COURSE

Chapter 56 - ICT5 Second Normal Form Definition Only applicable if table has a compound key A table is second normal form (2NF) if it is in first normal form (1NF) and no column that is not part of the primary key is dependent on a portion of the primary key: This may be said as : A table in 2NF contains no partial dependencies

Chapter 56 - ICT5 The STUDENT table the earlier slide (see above) is not in 2NF because, for example, student name is dependent only on student number and not on course number To put the tables in 2NF we need to introduce a third table to link the two entities Student numberStudent nameDate of birthSexCourse number 12345Jones, P20/05/1984MITA Phillips, K16/02/1983FITA Phillips, K16/02/1983FMUA Phillips, K16/02/1983FSPA Smith, J25/12/1984MMDA Smith, J25/12/1984MMUA201 etc

Chapter 56 - ICT5 The tables in 2 nd Normal Form (2NF) STUDENT (student number, student name, date of birth, sex) STUDENT_ COURSE(student number, course number) COURSE (course number, course name, lecturer number, lecturer name) What we had with the two entities was a many-to- many relationship This situation will always need a link table to create two one-to-many relationships

Chapter 56 - ICT5 Student numberStudent nameDate of birthSex 12345Jones, P20/05/1984M 22433Phillips, K16/02/1983F 66688Smith, J25/12/1984M etc Course numberCourse nameLecturer numberLecturer name ITA201A Level ICTT345267Moorcroft, E MDA201A Level MathsT666758Newton, I MUA201A Level MusicT773351Parry, D SPA201A Level SpanishT876541n/a etc Student numberCourse number 12345ITA ITA MUA SPA MDA MUA201 etc STUDENT COURSE STUDENT_COURSE

Chapter 56 - ICT5 Third Normal Form Definition A table in third normal form (3NF) contains no non-key dependencies In other words, the data in each entity (table) is checked to see if it relates entirely to the primary key, and not to any other attribute (i.e. field)

Chapter 56 - ICT5 The tables in 3 rd Normal Form (3NF) The COURSES table Contains an attribute for lecturer number and also one for lecturer name. Lecturer name is dependent on lecturer number (not on course number) Therefore a new table should be created for LECTURER

Chapter 56 - ICT5 Normalised Files STUDENT (student number, student name, date of birth, sex) STUDENT_COURSE (student number, course number) COURSE (course number, course name, lecturer number) LECTURER (lecturer number, lecturer name) This is the optimum way of holding this data, with no duplication. The tables in Relational Databases should be in Third Normal Form

Chapter 56 - ICT5 Comparing flat-files with RDB A relational database is able to create links between tables representing different entities such as STUDENT and COURSE, through the use of foreign keys. A flat file system is not able to link tables It is only useful for very simple databases which contain information about just one entity. It is impossible to ‘normalise’ a database in a flat file system, since this involves correctly establishing links between tables Flat-file systems do not have any of the sophisticated features of a full DBMS such as the ability to set individual user-access rights, or allow several people to access the database at the same time