36
Revised May 2012 St Andrew’s High School Computing Science Slide 1 Computing Science: Databases Databases Computing Science Level - National 4 / 5

Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Embed Size (px)

Citation preview

Page 1: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 1

Computing Science: Databases

Databases

Computing Science

Level - National 4 / 5

Page 2: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 2

Computing Science: Databases

What is a Database• A database is a structured collection of

similar information on one topic.• Examples:

– Phone book, library catalogue, criminal records, dictionary

• A database can be ordered either in ascending (A to Z) or descending (Z to A) order and on one or more fields.

• Example:– A phone book can be sorted by last name

and first name in ascending order (A to Z)

Page 3: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 3

Computing Science: Databases

Important Elements

• A database contains 3 important elements:– Fields– Records– Files

Page 4: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 4

Computing Science: Databases

Field• A field holds one piece of

information

Example:Forename HelenDate of Birth 12/12/95Town Coatbridge

Page 5: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 5

Computing Science: Databases

Record• A record is a collection of fields

on one person or thing.

Example:Your record in school would contain:

your name; date of birth; your address.

Page 6: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 6

Computing Science: Databases

File• A file is a collection of records on

the same topic.

Examples:- The Police National Computer - Customer records in a bank- Pupil files held on school computers

Page 7: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 7

Computing Science: Databases

Create and Add Records• Firstly the basic record structure is created by

deciding on the fields names and field types.• Secondly you must add new records

– You can add records through a form or just entering data straight to the table

Page 8: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 8

Computing Science: Databases

Alter Records

• Once you have created your database, you must ensure the data is correct.

• You can alter the records through a form, or through the table.

• You can also alter the record format.

Page 9: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 9

Computing Science: Databases

Field• A field is one single piece of

information

Example:- “name”, is one field this would be a text

field.- “date of birth”, is another field and this

would be a date field.

Page 10: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 10

Computing Science: Databases

Types of FieldsText holds letters, numbers and symbols

Numeric hold numbers for calculations

Date holds a date

Time holds a time

Graphic holds a picture

Calculated field performs a calculation on the contents of one or

more fields

Page 11: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 11

Computing Science: Databases

Types of Fields (contd.)

Link Stores a reference to an external media file or a connection to a related database table

BooleanOnly allows one of two values:yes/notrue/falsemale/female

Page 12: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 12

Computing Science: Databases

Field ValidationValidation ensures data entered is allowable and sensible

Range check:- Ensures the data entered in the field is between a lower and upper limit:e.g. Cost > £0 AND < £100

Time > 1 minAND < 5 mins

Length check:- Ensures that the data entered in the field has a restricted number of characters:e.g. PIN = 4 chars

Password >= 6 charsComments < 200 chars

Page 13: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 13

Computing Science: Databases

Field Validation (cont’d)Restricted choice

Gives the user a list of options to choose from. Prevents the user from typing in errors.e.g. Available dress sizes 8, 10, 12, 14, 16.

Presence check

Ensures that the field is not left blank.

Unique check Ensures that the data entered in the field is different from any other record.

Page 14: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 14

Computing Science: Databases

Creating a new Field• Fields can be

added at any time.

• When on the table view, select the design view option

• This view will allow you to enter a new field.

Page 15: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 15

Computing Science: Databases

SearchingThe search facility allows you to look for information in the database.

A search may be:Simple Look for records with a match on one field

( They have one thing in common.) Eg Hair = “Brown”

Complex Look for records with a match on more than one item in one or more fields.

Eg Hair = “Brown” AND

Eyes = “Blue”

Page 16: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 16

Computing Science: Databases

Eg. To find all records for 1st to 3rd year in a school database you could search for:

Year <= 3

Comparison operators< Less than< = Less than or equal to= Equal to> = Equal to or greater than> Greater than< > Not equal to

Contains

Page 17: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 17

Computing Science: Databases

SortingSorting allows you to arrange the records in a database in alphabetic or numeric order. This

can be ascending (A to Z or 1 to 9) or descending (Z to A or 9 to

1)Sorting on More than one field

When two items are the same in one field they can be separated using a second field for sorting.

For example, it is common to sort lists of names first by surname and then by first name

Page 18: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 18

Computing Science: Databases

Question TimeComplete the questions below from the Standard Grade Computing J Walsh book chapter 4, pages 63 and 64.NAT 4:

Foundation KU 1-3 and PS 1-5General KU 1-3 and PS 1

ORNAT 5:

Complete the booklet Page 1 - 4

Finish the questions above for next day.

Page 19: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 19

Computing Science: Databases

Calculated Field/ Computed FieldA calculated field allows you to carry out a

calculation on another field or fields and return the answer in the calculated field (similar to formulae in a spreadsheet).

Example: Field 1: Date of birthField 2: Today's dateField 3: Age Field 3 is a calculated field and contains

the formula: Today’s date - Date of birth

Other examples of calculated fields often used in reports include totals and sub-totals.

Page 20: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 20

Computing Science: Databases

Report

Any information on your database that you print out is a report. You would normally do a search and / or a sort, and then select which fields you want to print.

Page 21: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 21

Computing Science: Databases

This is the total number of characters, including spaces, needed to hold the information in a field.

Eg. A Field containing the data ‘Computing Department’Would have a field size of 20. Examples of databases

include:-Telephone directoryPolice National ComputerA personal Christmas card list.

Size of a field

Page 22: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 22

Computing Science: Databases

Calculating the storage requirements of a database file

Field Size of field

1 302 43 254 245 86 47 48 8

Page 23: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 23

Computing Science: Databases

Field Size Bytes required1 30 302 4 43 25 254 24 245 8 86 4 47 4 48 8 8

Total for one record= 107 bytesIf a database has 50 records the storage space required=

107 X 50 = 5350 bytes5350 / 1024 = 5.22 Kilobytes

Page 24: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 24

Computing Science: Databases

KeywordsThis is the text used to search a file for a particular entry.

Key FieldThis is a field which contains unique information for each record. That is, each record has a different number or text in the key field. Doing a search for an item on a unique field will only give one record.

Example: SQA has a database of all pupils attempting Standard Grade Exam. Each pupil has a unique candidate number because there will be more than one pupil with the same name and date of birth.

Page 25: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 25

Computing Science: Databases

Types of DatabaseFlat File database

Used to store information about one topic

Relational or Linked Database

Used to store information about several related topics.Each topic stored as a separate file or table.Database tables linked to create one large database.The tables are linked through a key field, referred to as a primary key in one table and a foreign key in the other table.e.g. Pupils database

Page 26: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 26

Computing Science: Databases

Linked/Relational Database Example

Pupils DatabasePupils table Registration Classes table

ForenameSurname

Date of BirthRegistration Class

Registration ClassRoom

Registration teacherRoom phone number

The two tables are linked by the same field being in both tables. This must be a key field in one of the tables.

Registration Class is the key field in the Registration Classes table because it uniquely identifies a single class. This is also referred to as the primary key.

The Registration Class field in the Pupils table is regarded as the foreign key.

Page 27: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 27

Computing Science: Databases

Data Protection ActDefinitions:

Data User is a person who holds and uses personal data about

others or controls the use of it.

Data Subject is a person about whom personal data is stored by a data user.

Page 28: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 28

Computing Science: Databases

The Data subjects have the following rights:

• to know if data is held about them on a computer

• to see a copy of this personal data• to make corrections if necessary• to ask for compensation if data is inaccurate or access given to an unauthorised person.

Page 29: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 29

Computing Science: Databases

Under the Data Protection Act (1984) data users must:• get and process the information fairly and lawfully• register what reason they hold it for• hold only relevant information • hold only accurate and up to date information• not keep information any longer than needed• give individuals access to information about themselves and, where necessary, correct or remove wrong information• take appropriate security measures.

Page 30: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 30

Computing Science: Databases

Exceptions to the Act

There are exceptions to people’s right to see data held about them. The public are denied access to data held by the Police or security forces.

Page 31: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 31

Computing Science: Databases

Misuse of ComputersThe Computer Misuse Act is intended to protect all types of information (not just

personal) stored on computer systems.

HackingThis is the act of trying to gain unauthorised entry to files. This is done by using a wide

area network and passwords.

Page 32: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 32

Computing Science: Databases

VirusesSome people enjoy writing and distributing computer viruses which destroy data and

cause computers to crash or take up processor time in meaningless calculations. Viruses are usually spread by copying files (from unofficial sources).

To prevent viruses spreading:• Don’t share disks.• Don’t copy software.• Use an anti-virus program to check

disks regularly.

Page 33: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 33

Computing Science: Databases

Mail MergeA database is the second general purpose package (along with a word processor) required to produce a mail merged document. Having studied both these packages, we are now in a better position to understand how a mail merge works.

Mail merging is the process of combining details from a database with a standard letter in a word processing package, to produce personalised letters - as many letters as there are records in the database.

Page 34: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 34

Computing Science: Databases

Name Flossie

Year S1

Name Josie

Year S5

Name Phyllis

Year S4

Database

Having created your database and your standard letter, you are ready to combine the two, filling the gaps in the standard letter with information from the database.

Dear Parent,

I am pleased to inform you that your child ___________ has won a prize for the best Computing student in __________ Head Teacher.

Word Processed Standard Letter

Page 35: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 35

Computing Science: Databases

Dear Parent,

I am pleased to inform you that your child <<Name>> has won a prize for the best Computing student in <<Year>>

Head Teacher.

Word Processed Standard Letter with database fields inserted ready for mail merge.

When the mail merge is performed the field names in brackets are replaced with the appropriate fields from the database. This is done for every record in the database.

The database field names are used to mark where in the standard letter information from the database will be inserted. These are shown in brackets like so << >> to mark them.

Page 36: Slide 1 Computing Science: Databases Revised May 2012 St Andrew’s High School Computing Science Databases Computing Science Level - National 4 / 5

Revised May 2012 St Andrew’s High School

Computing ScienceSlide 36

Computing Science: Databases

Question TimeComplete the questions below from the Standard Grade Computing J Walsh book chapter 4, pages 63 and 64.

Credit KU 1 and PS 1-2and

Page 5 and 6 from the Database Booklet

Complete questions for next day.

Copy key points into your jotter.