Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database revision for higher

Similar presentations


Presentation on theme: "Database revision for higher"— Presentation transcript:

1 Database revision for higher

2 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

3 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

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

5 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.

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

7 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.

8 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?

9 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 an error should appear!

10 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.

11 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:

12 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!

13 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.

14 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 12/4/13 19/4/13 Fishing 013 Smith Emma 17 Main Street Carnoustie DD7 5VF Mother’s Curse 20/4/13 067 Roberts Susan The Elms DD7 8HG My Life 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

15 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

16 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 12/4/13 19/4/13 Fishing 013 Smith Emma 17 Main Street Carnoustie DD7 5VF Mother’s Curse 20/4/13 067 Roberts Susan The Elms DD7 8HG My Life 18/4/13 24/4/13

17 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

18 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

19 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 *

20 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.

21 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?

22 Structures and links (Database)
Higher Computing Science

23 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)

24 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

25 Example of normalisation
Bits ‘N’ PCs Example of normalisation

26 Bits ‘n’ PCs Limited Bits ‘n’ PCs Limited
Order number: Order Date: 01/02/2004 Customer Number: Name: Mrs Joanna Bloggs Address: 12 High Street Auchenshoogle Inverness-shire Postcode: IV99 2QW Telephone No: 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

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

28 Large deluxe widget (red) Small economy widget (green)
Bits ‘n’ PCs Limited Bits ‘n’ PCs Limited Order number: 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: 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

29 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 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

30 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)

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

32 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

33 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

34 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 .....

35 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

36 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

37 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

38 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

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

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

41 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:-  

42 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

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

44 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

45 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

46 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

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

48 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

49 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

50 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

51 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

52 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 ..... ....

53 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)

54 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

55 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

56 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”

57 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.

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

59 ... And another example of exam question about complex database operations
The report includes a single total of £ 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


Download ppt "Database revision for higher"

Similar presentations


Ads by Google