Databases and Boolean Logic Worksheet
Databases and Boolean Logic Worksheet
Table: ................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
Record: .............................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
Field: ................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
b Identify four basic data types used in a database and provide an example for each one.
1 ......................................................................................................................................................................
......................................................................................................................................................................
......................................................................................................................................................................
2 ......................................................................................................................................................................
......................................................................................................................................................................
......................................................................................................................................................................
3 ......................................................................................................................................................................
......................................................................................................................................................................
......................................................................................................................................................................
4 .....................................................................................................................................................................
......................................................................................................................................................................
......................................................................................................................................................................
Photocopying prohibited
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: ............................................................................................................................................................
Field 3: ............................................................................................................................................................
Reason: ............................................................................................................................................................
...........................................................................................................................................................................
Sample: ............................................................................................................................................................
Field 4: ............................................................................................................................................................
Reason: ............................................................................................................................................................
...........................................................................................................................................................................
Sample: ............................................................................................................................................................
Photocopying prohibited
56 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
9 Databases
Field 5: ............................................................................................................................................................
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.
Photocopying prohibited
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
......................................................................................................................................................................
......................................................................................................................................................................
Photocopying prohibited
58 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
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.
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
Photocopying prohibited
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.
......................................................................................................................................................................
......................................................................................................................................................................
......................................................................................................................................................................
......................................................................................................................................................................
Photocopying prohibited
60 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
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.
......................................................................................................................................................................
......................................................................................................................................................................
Photocopying prohibited
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
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.
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
Photocopying prohibited
62 Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
10 Boolean logic
1 State the logic gate each truth table represents.
a b A B X
c A B X
A B X
0 0 0 0 0 1 0 0 0
0 1 1 0 1 1 0 1 1
1 0 1 1 0 1 1 0 1
1 1 1 1 1 0 1 1 0
A
B
A B C Working area X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook Photocopying prohibited 63
10 Boolean logic
...........................................................................................................................................................................
...........................................................................................................................................................................
A B Working area X
0 0
0 1
1 0
1 1
.................................................................................................................................................................................
Photocopying prohibited Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
64
10 Boolean logic
A B C Working area X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
.................................................................................................................................................................................
.................................................................................................................................................................................
B X
A B C Working area X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook Photocopying prohibited
65
10 Boolean logic
...........................................................................................................................................................................
7 a Write down the logic expression to represent the following logic circuit:
A
B X
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
b Draw the logic circuit which corresponds to the following truth table:
A B C X
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
B X
Photocopying prohibited Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
66
10 Boolean logic
8 A chemical process is monitored using a logic circuit. There are three inputs to the logic circuit
representing the parameters being monitored in the chemical process. An alarm, X, will give an
output value of 1 depending on certain conditions.
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
...........................................................................................................................................................................
A X
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook Photocopying prohibited
67
10 Boolean logic
T A P Working area X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
9 A safety system uses the input from three sensors A, B and C. The binary values from these sensors
form the input to a logic circuit.
Sensor A
Sensor B Logic circuit 'X' Output, X, from logic circuit
Sensor C
B X
Photocopying prohibited Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
68
10 Boolean logic
A B C Working area X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
c For safety reasons, the sensors feed into three different logic circuits (numbered 1, 2 and 3)
which produce the outputs X, Y and Z. These three outputs then form the inputs to another
logic circuit which has the output Q.
The three logic circuits are connected to this extra logic circuit:
Logic Output X
circuit 1
inputs
from
the Output Y
Logic
three
circuit 2 Q
sensors
A, B
and C
Logic Output Z
circuit 3
X Y Z Working area Q
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook Photocopying prohibited
69
10 Boolean logic
B X
A B C Working area X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
A B X
0 0 1
0 1 0
1 0 0
1 1 1
Photocopying prohibited Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
70
10 Boolean logic
12 a Draw a logic circuit for this logic expression. Each logic gate must have a maximum of
two inputs and the expression must not be simplified:
A B C Working area X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook Photocopying prohibited
71
10 Boolean logic
Photocopying prohibited Cambridge IGCSE and O Level Computer Science Algorithms, Programming and Logic Workbook
72