Chapter 9 - Database
Chapter 9 - Database
Introduction 4
7 Algorithm design and problem solving 5
8 Programming 26
9 Databases 55
10 Boolean logic 63
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
3
9 Databases
1 a Explain the meaning of the following database terminology.
Table: ................................................................................................................................................................
...........................................................................................................................................................................
............................................................................................................................. ..............................................
Record: .............................................................................................................................................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
Field: ................................................................................................................................................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
b Identify four basic data types used in a database and provide an example for each one.
1 ......................................................................................................................................................................
......................................................................................................................................................................
............................................................................................................................. .........................................
2 ......................................................................................................................................................................
............................................................................................................................. .........................................
................................................................................................................................. .....................................
3 ......................................................................................................................................................................
............................................................................................................................. .........................................
..................................................................................................................................... .................................
4 .....................................................................................................................................................................
............................................................................................................................. .........................................
............................................................................................................................................. .........................
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
55
9 Databases
2 A single-table database, ICECREAM, has been set up to store the ice creams available for sale.
The details included about each type of ice cream are:
» Type – for example, 'choc ice', 'lolly' or 'cone'
» Flavour – for example, 'raspberry'
» Size – 'Small', 'Medium' or 'Large'
» Number in stock – for example, '34'
» Re-order level – for example, '20'.
a Write down names for the five fields that would be required. For each field state with a
reason the data type that should be used and give a sample of the contents of that field.
Field 1: ............................................................................................................................................................
Reason: ............................................................................................................................................................
............................................................................................................................. ..............................................
Sample: ............................................................................................................................................................
Field 2: ............................................................................................................................................................
Reason: ............................................................................................................................................................
..................................................................................................................... ......................................................
Sample: ............................................................................................................................................................
Reason: ............................................................................................................................................................
............................................................................................................................................... ............................
Sample: ............................................................................................................................................................
Reason: ............................................................................................................................................................
............................................................................................................................. ..............................................
Sample: ............................................................................................................................................................
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
56
9 Databases
Reason: ............................................................................................................................................................
............................................................................................................................. ..............................................
Sample: ............................................................................................................................................................
............................................................................................................................. .........................................
......................................................................................................................................................................
............................................................................................................................. .........................................
..................................................................................................................................... .................................
ii Give the reason why none of the existing fields are suitable to use as a primary key.
............................................................................................................................. .........................................
......................................................................................................................................................................
iii Give a suitable field name, data type and sample for another field that could be used
as a primary key.
Name: ..........................................................................................................................................................
......................................................................................................................................................................
Sample: .....................................................................................................................................................
c Build the database table as specified in parts a and b. Write or paste a copy of your table
structure here.
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
57
9 Databases
d Populate the database table with six records. Write or paste a copy of your populated table here.
............................................................................................................................. ..............................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
............................................................................................................................. ..............................................
i SELECT
............................................................................................................................. .........................................
....................................................................................................................................... ...............................
......................................................................................................................................................................
............................................................................................................................. .........................................
ii FROM
............................................................................................................................. .........................................
......................................................................................................................................................................
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
58
9 Databases
iii WHERE
............................................................................................................................. .........................................
......................................................................................................................................................................
............................................................................................................................. .........................................
..................................................................................................................................... .................................
iv SUM
......................................................................................................................................................................
............................................................................................................................. .........................................
............................................................................................................................. .........................................
......................................................................................................................................................................
c Identify two more SQL statements that you need to know for IGCSE Computer Science.
1 ......................................................................................................................................................................
2 ......................................................................................................................................................................
d Use the six statements from parts b and c to write SQL queries for the database table you
created in Question 2 to:
» Show the types, in alphabetical order, and sizes of all the ice creams that are in stock
» Show the total number of ice creams available to buy
» Count the number of ice creams that have stock below the reorder level.
Write or paste a copy of your SQL queries here.
............................................................................................................................. ..............................................
...........................................................................................................................................................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
............................................................................................................................. ..............................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
............................................................................................................................. ..............................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
59
9 Databases
4 A single-table database, TEACHER, contains the details of the teachers in a school. The database
includes these fields:
a i Identify the field that would be most suitable to use as a primary key. Give a reason
for your choice.
............................................................................................................................. .........................................
............................................................................................................................. .........................................
......................................................................................................................................................................
............................................................................................................................. .........................................
ii State the data type that could be used for each field.
Name: ..........................................................................................................................................................
Title: ...........................................................................................................................................................
Licence: ......................................................................................................................................................
Gender: .......................................................................................................................................................
Subject: ......................................................................................................................................................
Class: ..........................................................................................................................................................
b i Identify a field that should be verified. Give a reason for your choice.
............................................................................................................................. .........................................
........................................................................................................................................... ...........................
...................................................................................................... ................................................................
............................................................................................................................. .........................................
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
60
9 Databases
ii Identify a field that could be validated. Give a reason for your choice.
............................................................................................................................. .........................................
......................................................................................................................................................................
............................................................................................................................. .........................................
........................................................................................................................................ ..............................
Yo Mr L4579 M Mathematics 3Z
............................................................................................................................. .........................................
......................................................................................................................................................................
............................................................................................................................. .........................................
............................................................................................................................. .........................................
......................................................................................................................................................................
............................................................................................................................. .........................................
iii Rewrite this SQL statement to include the mathematics teachers as well.
............................................................................................................................. .........................................
...................................................................................................................................................... ................
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook Photocopying prohibited
61
9 Databases
iv Write a new SQL statement to count the number of mathematics teachers in the TEACHER
table.
d Write an SQL statement to display the names of all the teachers and their classes in
ascending order of class.
............................................................................................................................. ..............................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
............................................................................................................................. ..............................................
............................................................................................................................. ..............................................
...........................................................................................................................................................................
............................................................................................................................. ..............................................
............................................................................................................................. ..............................................
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
62