Database revision for higher

Slides:



Advertisements
Similar presentations
Relational Database Systems Higher Information Systems Advanced Implementation in MySQL/PHP.
Advertisements

Relational Database Systems Higher Information Systems.
Normalisation.
Organisation Of Data (1) Database Theory
DATABASE RC D DD CMA C M R B PK E I S H S RC H L I V FK.
WHAT D IS RAW, UNPROCESSED FACTS AND FIGURES COLLECTED, STORED AND PROCESSED BY COMPUTERS.
Relational Database Systems Higher Information Systems.
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.
Relational Database Systems Higher Information Systems.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
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?
Database Design IST 7-10 Presented by Miss Egan and Miss Richards.
Software Development Unit 2 Databases What is a database? A collection of data organised in a manner that allows access, retrieval and use of that data.
2.3 Organising Data for Effective Retrieval
Modelling Techniques - Normalisation Description and exemplification of normalisation.Description and exemplification of normalisation. Creation of un-normalised.
Driving School Database
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Designing a Database (Part I) -Identify all fields needed to produce the required information -Group related fields into tables -Determine Each Table’s.
Microsoft Access – Tutorial 2 Designing Databases In this tutorial, we will create a new database create a new table import tables from an existing database.
Slide 1 Standard Grade Computing Databases. Slide 2 Standard Grade Computing Definitions DatabaseA database is a structured collection of similar information.
Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5.
Databases The Kingsway School. Database Systems Databases are programs which store information in a logical way. Databases have a structure which helps.
1 n 1 n 1 1 n n Schema for part of a business application relational database.
System Development Lifecycle Verification and Validation.
Information Systems & Databases 2.2) Organisation methods.
ITGS Databases.
Relational Databases. Relational database  data stored in tables  must put data into the correct tables  define relationship between tables  primary.
Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used.
Case Study 1 Normalisation - the easy way? Read Case Study 1 produce a 3NF. show consideration of UNF, 1NF and 2NF.
Databases 101 © Dolinski What you will learn How relational databases work What are the components that make up a database How to create each component.
Do it now activity Activity: A travel agent is trying to create a database to collect information about people who are booking a flight. He is having a.
Mr C Johnston ICT Teacher
Topic 3 – Data Modeling Techniques Unit 1 – Database Analysis and Design Advanced Higher Information Systems St Kentigern’s Academy.
Sample Table Standard Notation Entity name in uppercase
Description and exemplification use of a Data Dictionary. A data dictionary is a catalogue of all data items in a system. The data dictionary stores details.
Information Systems Database Systems (H).
Software. Because databases can get very big, it is important to decide exactly what is going to be stored in each field. Fields can be text, number,
Normalisation Unit 6: Databases. Just to recap  What is an Entity  What is an Attribute?
BTEC NCF IT Unit 02 Creating Systems to Manage Information Lesson 05 – Data Types Mr C Johnston.
N5 Databases Notes Information Systems Design & Development: Structures and links.
Relational Databases This topic forms part of the ISDD unit in Higher Computer Science. An introduction was made to the relational database model at Nat.
DATA TYPES.
IGCSE 4 Cambridge Designing a database table Computer Science
Lesson 10 Databases.
Creating a database table
Databases Chapter 9 Asfia Rahman.
Guidelines for Designing Databases
Databases.
Microsoft Office Access 2010 Lab 2
Practical Office 2007 Chapter 10
© The McGraw-Hill Companies, All Rights Reserved APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
Unit 16 – Database Systems
Week 12 Option 3: Database Design
Database Design and Development
Entity relationship diagrams
GCSE Computing Databases.
Databases Software This icon indicates the slide contains activities created in Flash. These activities are not editable. For more detailed instructions,
Data Types & File Size Calculations
Database Normalisation
Database Theory.
Database Design and Development
Computer Science Projects Database Theory / Prototypes
Databases.
Spreadsheets, Modelling & Databases
The ultimate in data organization
ICT Database Lesson 2 Designing a Database.
Databases This topic looks at the basic concept of a database, the key features and benefits of a Database Management System (DBMS) and the basic theory.
Presentation transcript:

Database revision for higher

Field Types Text – Mixture of letters, words, numbers and/or symbols. Can’t perform a calculation on a number in a text field. Number Integer – whole numbers. Real – decimal/floating point numbers. Date Time

Field Types - continued Graphic Calculated – field containing a formula. Link - a hyperlink to a file outside the database. The file could be a web page or a document. Boolean - holds one of two values. E.g. Yes/No Object – field that contains a variety of different types of data such as a presentation, audio, video or graphic

Calculated field Uses the values in another field or fields to calculate the contents of a new field.

Validation Validation is used to make sure that a user only inputs data in the correct format. If the user makes an error the database will display an error message and ask the user to re-enter.

Validation 4 different types of validation: Presence Check Restricted Choice Field Length Range Check

Presence check When a presence check is set up on a field, that field cannot be left blank, some data must be entered into it. The presence check does not check that the data is correct, only that some data is present. You may have used this before when completing an online form. If you try to leave a field blank you will be asked to go back and enter information into the field.

Restricted Choice When a restricted choice check is added to a field it gives the user a list of options that they can select. Saves time & reduces the amount of errors entered. Can you give some other examples of restricted choice checks you have used when entering a form on the internet?

Field length A Database designer will restrict the field length to: Save the amount of memory a database file takes up. Stop someone from entering too many characters into a field. E.g. If a user inputs a telephone number of 123456789101112131415117181912020 an error should appear!

Range check The range of a field refers to the acceptable range of values it will accept. E.g. if a field holds the month as a number from 1 (January) to 12 (December) then the range is 1 to 12 >=1 and <=12 If a number outside the range is typed in an error message will appear.

Types of Database The two main types of computerised databases are flat-file and relational. Flat-File – a flat file database is stored in a single table:

Flat file database problems Data is duplicated – when a new record is created the member details and game details would have to be entered Data duplication wastes space on backing storage Data duplication increases the chance of human error when typing in the same customer’s details or game details a number of times or when changing data A customer’s details can only be recorded when they rent something Removing a game from the database may remove the only record that stores details of a member. The member details will be lost!

Flat file database problems Insertion Problems – adding a record - it is not possible to store details of a game without a member taking it out. Deletion Problems – deleting a record - if a game is deleted it may delete the only occurrence of a member. Update Problems – changing a record - if a member changes their name or address more than one record would need to be updated.

Library Flat File Database System Example ID surname forename address town post code book ISBN date borrowed returned 001 Bell John 23 High Street Arbroath DD7 5FT Fiction in Action 0091870364 12/4/13 19/4/13 Fishing 0071675439 013 Smith Emma 17 Main Street Carnoustie DD7 5VF Mother’s Curse 20/4/13 067 Roberts Susan The Elms DD7 8HG My Life 00634 89654 18/4/13 24/4/13 There are a number of problems associated with storing the data in this form as a single table. Can you spot the: Insertion Problem Deletion Problem Update Problems

solving flat file database problems Create a Relational database i.e. linked table database stores data in more than one table stores data once remove the possibility of data duplication and data inconsistency

Linked Tables/Relational Database The previous table contains multi-valued fields. The fields subject, ISBN, date borrowed and date returned contain more than one value for the member John Bell. ID surname forename address town post code book ISBN date borrowed returned 001 Bell John 23 High Street Arbroath DD7 5FT Fiction in Action 0091870364 12/4/13 19/4/13 Fishing 0071675439 013 Smith Emma 17 Main Street Carnoustie DD7 5VF Mother’s Curse 20/4/13 067 Roberts Susan The Elms DD7 8HG My Life 00634 89654 18/4/13 24/4/13

Linked Tables/relational database Remove the repeating values and place them in a table of their own Library database:- MEMBER (MemberID, Surname, Forename, Address, Town, Postcode) LOAN (ISBN, Book, DateBorrowed, DateReturned, *MemberID) MemberID is the primary key in the MEMBER table. ISBN & Member ID are the primary key in the LOAN table. MemberID is a foreign key in the LOAN table

Primary Key A field or set of fields that uniquely identify a record E.g. In a customer table, there may be a number of clients called John Smith so to uniquely identify which John Smith there could be a key field called Customer ID Primary keys are underlined What primary key would be used to identify you in the following databases: School SQA Doctors Surgery Dentist

Foreign Key A field that links two tables together It is not a primary key in its own table, but is a primary key in another table Library example – Member ID is the primary key in the customer table and the foreign key in the loan table MEMBER(MemberID, Surname, Forename, Address, Town, Postcode) LOAN(ISBN, Book, DateBorrowed, DateReturned, *MemberID) Foreign keys are indicated by a star *

Hardware Database Example Can you spot the multi-valued fields? Can you spot data duplication? Now try to turn this into a linked table and solve the problems above.

Hardware Database Example Solve flat-file database problemswe split the table into 2 tables by removing the repeating values into a table of their own and creating primary keys. Now there is no connection between orders and customers. What should we do to fix this?

Structures and links (Database) Higher Computing Science

What you need to know and do Implementation of relational databases with a minimum of three linked data tables Description, implementation and exemplification of compound keys and surrogate keys Description, exemplification and identification of entity relationships (one-to-one, one-to-many, many-to-many) Description, exemplification and implementation of entity relationship diagrams Description and implementation of complex database operations including: input (forms) searching/sorting/calculations (queries) output (reports)

Implementation of relational databases with a minimum of three linked data tables Data modelling is used to decide which tables and fields are required There follows examples of 3 databases so that you understand why the tables exist and why contain those fields You do not need to be able to carry out the process of normalisation

Example of normalisation Bits ‘N’ PCs Example of normalisation

Bits ‘n’ PCs Limited Bits ‘n’ PCs Limited Order number: 654321 Order Date: 01/02/2004 Customer Number: 234567 Name: Mrs Joanna Bloggs Address: 12 High Street Auchenshoogle Inverness-shire Postcode: IV99 2QW Telephone No: 01999 123456 Total: £19.69 Item Code Description Unit Cost Quantity Sub-Total 1170 Medium widgets (blue) £2.25 3 £6.75 5499 Large deluxe widget (red) £9.99 1 7937 Small economy widget (green) £0.59 5 £2.95

Un-normalised form Write down all the attributes that must be stored Identify a primary key

Large deluxe widget (red) Small economy widget (green) Bits ‘n’ PCs Limited Bits ‘n’ PCs Limited Order number: 654321 Order Date: 01/02/2004 Customer Number: 34567 Customer Name: Mrs Joanna Bloggs Address: 12 High Street Auchenshoogle Inverness-shire Postcode: IV99 2QW Telephone No: 01999 123456 Total: £19.69 Order( Order_number Order_date Customer_number Customer_name Address Postcode Telephone_no Item_code Description Unit_cost Quantity) Item Code Description Unit Cost Quantity Sub-Total 1170 Medium widgets (blue) £2.25 3 £6.75 5499 Large deluxe widget (red) £9.99 1 7937 Small economy widget (green) £0.59 5 £2.95

Sample data Multi-valued attributes = repeating data items Oder_number Order_date Customer_number Customer_name Address Postcode Telephone number Item Code Description Unit Cost Quantity 654321 1/9/04 234567 Mrs Joanna Bloggs 12 High Street Aunchenshoogle Inverness-shire IV99 2QW 01999 123456 1170 Medium widgets (blue) £2.25 3 5499 Large deluxe widget (red) £9.99 1 7937 Small economy widget (green) £0.59 5 Multi-valued attributes = repeating data items

Un-normalised Form with repeating data items identified Order ( Order_number Order_date Customer_number Customer_name Address Postcode Telephone_no Item_code Description Unit_cost Quantity)

First Normal form Remove all multi-valued attributes to a new entity

Customer UNF 1NF 2NF 3NF Order ( Order_number Order_date Customer_number Customer_name Address Postcode Telephone_no Item_code Description Unit_cost Quantity) Order ( Order_number Order_date Customer-_number Customer_name Address Postcode Telephone_no) Order ( Order_number Order_date *Customer-_number) Customer_name Address Postcode Telephone_no) Customer (Customer_number Item_code Description Unit_cost Quantity) Order_item ( *Order_number *Item_code Quantity) Order_item ( *Order_number Order_item ( *Order_number *Item_code Quantity) Description Unit_cost item (Item_code item (Item_code Description Unit_cost

Description, implementation and exemplification of compound keys and surrogate keys a primary key that consists of more than one field uniquely identifies a record used when there is no primary key – i.e. no single attribute (field) that stores a unique value for each entity occurrence (record) E.g. Oder_number and Item_code in the Order_item table Surrogate key:- a primary key that is created to uniquely identify a record when there is no primary key or when a compound key is not attractive e.g. has 3 fields E.g. Item_code, Customer_number

Description, exemplification and identification of entity relationships (one-to-one, one-to-many, many-to-many) In your Genius Guide:- One-to-one - a primary key links one record in one table to one record in another table, where it is a foreign key One-to-many - a primary key links one record to more than one record in another table, where it is a foreign key Many-to-many– when read in both directions – read one-to-many from left to right and one-to-many from right to left The full story follows .....

E/R occurrence modelling Systems analyst uses E/R occurrence modelling to identify relationship between two entities To create an E/R occurrence diagram the systems analyst must fully understand the system and have sample data

Drawing an E/R occurrence diagram 1. Create a list of primary key values Van Reg P385 ASA KY51 AFZ YT71 7YE D842 YSA Client Nbr 2711 0921 2. Link primary keys

What is the point of an E/R occurrence diagram? Pattern of lines identifies nature of relationship between the two entity sets 3 possible patterns. One pattern for each relationship cardinality:- 1 to 1 1 to many Many to many

1 to 1 relationship Create a list of primary key values Link key values Computer name Paris Washington London Geneva Edinburgh Payroll number 030/829112 040/881929 040/546781 030/112000 050/444878

1 to Many Relationship Course code CC871 CC101 CC891 Student ID NW872818C RT77712C UI828211E NQ829111D NW872819C

Many to Many Relationship Food supplier Beefy soup Co. Baters Ltd Luxury Soup McCampbells Outlet Big store ADSA Market SafeCo

Description, exemplification and implementation of entity relationship diagrams Created by a systems analyst to illustrate the entities (tables) and the relationships that exist between them that were identified when designing the database Picture of entities, relationships, (attributes/fields) and cardinality Example:-  

Entity Relationship Diagram Order ( Order_number Order_date *Customer-_number) Customer (Customer_number Customer_name Address Postcode Telephone_no) Order_item ( *Order_number *Item_code Quantity) item (Item_code Description Unit_cost) Entity Relationship Diagram Order Customer Order_item Item

Example of normalisation and ER diagram Application Forms Example of normalisation and ER diagram

Application form Application no: 56 Applicant no: 118 Applicant name: Johnathon Appleby Date of birth: 3/2/1990 Applicant Address: 3 Sycamore Street Valleyfield Aberdeen AB65 WY65 Course code: GD65 Course title: Information Systems Date received: 7/11/2006 Qualification code Qualification Title Grade Obtained DT567 S Grade Maths 1 KU786 S Grade English FE453 S Grade Computing MK897 S Grade History DS432 S Grade French 2 ML987 S Grade Art & Design DP874 S Grade Chemistry CD432 S Grade Physics

Entities and attributes Application Applicant Course Qualification Qual_code Application_no *Applicant_no *Course_code Date_received Applicant_no Applicant _name Applicant_address Date_of_birth Course_code Course_title *Application_no *Qualification code Grade_obtained Qualification code Qualification_title Identify a surrogate key and a compound key Draw an ER diagram

Draw the ER Diagram for Application forms Application (Application_no *Applicant_no *Course_code Date_received) Applicant (Applicant_no Applicant_name Applicant_address Date_of_birth) Course (Course_code Course_title) Qualification (*Application_no *Qualification code Grade_obtained) Qual_code (Qualification code Qualification_title) Applicant Course Application Qualification Qual_code

ER diagrams For you to do Room service Films Sports Day Zoo ICT Courses

Exemplification and implementation of data dictionary including name, type, size, required and validation  Created when designing a database Shows the structure of tables and the properties of fields A table that lists the attributes(fields) of each entity (table) with their properties:- Name Type Size Required Validation

Basic rules used when naming attributes (fields) and entity sets (tables) The names must be suitable for most database packages:- Use lower case letter No spaces – use underscore _ Meaningful names Keep it short e.g customer_tel_nbr

Data dictionary columns Entity set – becomes the name of the table when it’s created on the computer Name – names of attributes that will become field names in the database table Type – data held in the attribute will be constrained by type (Ch3). Text, integer, Boolean, real, object, link date & time Size – text attributes are constrained by maximum length Required - indicates whether the field may be null Validation- next slide

Data dictionary columns (cont’d) Validation – each attribute is constrained by the range of acceptable values. 4 types of validation check:- Presence - whether null values are allowed Range - above/below/between certain values Permitted values -one of a selection of values is allowed Format - data must conform to specific pattern and/ number of characters PK/FK – identifies primary and foreign keys

Data dictionary example Table name Field name Key Type Size Required Validation DVD DVD Code PK Integer Y Film Code FK Text 4 Look up the Film table Cost Currency Range check >=1 and <=3 MEMBER Member number Title Restricted choice Mr/Mrs/Miss/Ms Forename 15 ..... ....

Order ( Order_number Order_date *Customer-_number) Customer (Customer_number Customer_name Address Postcode Telephone_no) Order_item ( *Order_number *Item_code Quantity) item (Item_code Description Unit_cost)

Description and implementation of complex database operations Input (forms):- used to provide a simple form for entering data  Query: – used to search a database for records that match criteria used to sort data into order calculated field - generates its value other field(s) in a table Output (reports):- used to generate a printable copy of the output from a query formatted to look good can also sort or carry out calculations

Example of exam question about complex database operations Pupil Course Choice Teacher pupil ID course ID pupil ID * teacher ID pupil name course title course ID* teacher name date of birth level teacher ID* room no register class department  Describe how this report was generated:- pupil ID: 2453 course title level teacher name room no Computing Science National 5 Mrs Forbes B210 Business Management Mr Brown B209 Administration & IT Mrs Stirling B108

Answer - Description of complex database operations “Create a query with the following fields: Pupil.pupil ID = 2453 Course.course ID Course.level Teacher.teacher name Teacher.room no And then create a report using the data from the query”

Further Example of exam question about complex database operations A report is produced each time a customer makes an order. An example is shown:- This report is based on a query. State a list of the tables and fields that would be used in this query and any criteria that would be used to select the above data.

Answer - Description of complex database operations Customer.Customer No Order.Order No Order.Quantity Item.Description Item.Unit Cost   [Customer.Customer No] = 5284

... And another example of exam question about complex database operations The report includes a single total of £189.00 after the two subtotals. Describe how this can be done in the report  Answer:- SUM([Order.Qty]*[Item.Cost]) is placed in the Report Footer