Databases and SQL – IGCSE Computer Science (0478)
Quick quiz: 10 random questions from this topic. Answer them all, then open the Summary.
Question text
6
An algorithm has been written in pseudocode to allow 100 positive numbers to be input. The total
and the average of the numbers are output.
100
01
Counter
0
02
Total
03
WHILE Counter > 100 DO
04
INPUT Number
05
IF Number > 0
06
THEN
Total + Counter
07
Total
Counter + 1
08
Counter
09
ENDCASE
10
ENDWHILE
11
OUTPUT "The total value of your numbers is ", Total
12
OUTPUT "The average value of your numbers is ", Total / 100
(a) Identify the four errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Describe the changes you should make to the corrected algorithm so that a count-controlled
loop is used to allow 100 positive numbers to be input.
You do not need to rewrite the algorithm.
…
…
…
…
…
…
…
…
…
… [5]
Question text
A database table called SoftDrinks stores details of the soft drinks sold by a small shop.
9
Field
Example data
Name
Cola
Supplier
Cambridge Beverages
Container
Can
SizeCl
330
NumberInStock
30
ReorderLevel
15
Reordered
Yes
(a) State whether any of the given fields would be suitable as a primary key and give a reason for
your answer.
…
… [1]
(b) Complete the structured query language (SQL) statement to return the number of cans the
shop has in stock.
SELECT … ( … )
FROM …
WHERE … = … ;
[5]
Question text
5
A database table, COMPUTER, is used to keep a record of computers available for sale.
The following data is stored for each computer:
•
CATEGORY – desktop, laptop or tablet
•
WEIGHT – weight in kilograms
•
MANUFACTURER – ICN, Linoldo, Pear or JoeSing
•
PRICE – price in $
•
CODE – a unique code allocated by the manufacturer, e.g. P771
•
STOCK – quantity in stock.
A database management system uses these data types:
Text
Number
Currency
Boolean
The CATEGORY field and MANUFACTURER field have a data type of text.
(a) Select the most appropriate data type for each field from the four types shown. State the
reason why you chose the data type.
WEIGHT data type …
Reason …
…
PRICE data type …
Reason …
…
CODE data type …
Reason …
…
STOCK data type …
Reason …
…
[4]
(b) Complete the query-by-example grid to display only the category, manufacturer, price and
code of the computers with weight of less than 2.5 kilograms.
Field:
Table:
Sort:
Show:
Criteria:
or:
[3]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Question text
4
An algorithm is written in pseudocode:
0
Total
1 TO 50
FOR Count
INPUT Num
Total + Num
Total
NEXT Count
OUTPUT Total
(a) Describe the purpose of the algorithm.
…
…
…
…
…
… [3]
(b) Re-write the algorithm in pseudocode using a different type of loop.
…
…
…
…
…
…
…
…
…
… [3]
(c) Describe how you could modify the original algorithm shown at the start of question 4, to
allow any number of inputs.
…
…
…
… [2]
Question 5 starts on page 12.
Question text
4
The algorithm shown by this flowchart allows the input of examination marks for a class of students.
A mark of –1 ends the process. If a mark is 80 or over then a distinction grade is awarded. The
number of distinctions for the whole class is calculated. If this is over 50% of the class, the class is
awarded a highly commended certificate.
START
← 0
← 0
Counter
Distinction
INPUT
Mark
← Distinction/Counter
Yes
IS
Award
Mark = –1?
No
← Counter + 1
Yes
OUTPUT
IS
Counter
"Highly
Award > 0.5?
Commended"
No
← Distinction + 1
Distinction
END
IS
Yes
Mark >= 80?
No
Complete a trace table for the algorithm using this input data:
88, 74, 60, 90, 84, 87, 95, 72, 84, 66, –1
Counter
Distinction
Mark
Award
OUTPUT
[5]
Question text
6
A database, STAFFPHONE, was set up to show the telephone extension numbers for members of
staff working in a department store.
Name
Department
Extension number
Jane Smith
Toys
129
Sue Wong
Books
124
David Chow
Toys
129
Amy Tang
Household
123
Joe Higgs
Books
124
Jane Smith
Shoes
125
Adel Abur
Shoes
125
Peter Patel
Toys
129
(a) Explain why none of the fields in the database can be used as a primary key.
…
…
… [2]
(b) State a field that could be added as a primary key.
…
Give a reason for choosing this field.
…
… [2]
(c) Use the query-by-example grid below to provide a list of all members of staff, in alphabetical
order, grouped by department.
Field:
Table:
Sort:
Show:
Criteria:
or:
[5]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
7
A teacher has decided to use a database table as her mark book for her Computer Science class,
which she has called MARKBOOK. For each student, the following data will be recorded: first
name, last name, their year 10 test score and their year 11 test score. The class has 32 students.
(a) State the number of fields and records required for this database.
Number of Fields …
Number of Records …
[2]
(b) The data in MARKBOOK is stored under category headings: LastName, FirstName,
Y10TestScore and Y11TestScore.
State, with a reason, whether any of these headings would be suitable as a primary key.
…
…
…
… [2]
(c) Complete the query-by-example grid to only display the first name, last name and year 10
test score of each student who achieved 50 or more in their year 10 test. The output should
be in test score order with the highest marks at the top of the list.
Field:
Table:
Sort:
Show:
Criteria:
or:
[4]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Question text
10 A database table called TVRange shows the main features and prices of a range of televisions.
TVCode
ScreenSize
Satellite
SmartTV
SoundBar
Price$
TV90SaSmSd
90
YES
YES
YES
9750.00
TV75SaSmSd
75
YES
YES
YES
8500.00
TV75SaSd
75
YES
NO
YES
8000.00
TV65SaSmSd
65
YES
YES
YES
6000.00
TV65SmSd
65
NO
YES
YES
5000.00
TV65SaSd
65
YES
NO
YES
5000.00
TV55SaSmSd
55
YES
YES
YES
4000.00
TV55SaSd
55
YES
NO
YES
3500.00
TV55SmSd
55
NO
YES
YES
3500.00
TV50SaSmSd
50
YES
YES
YES
2500.00
TV50Sa
50
YES
NO
NO
1750.00
TV50Sm
50
NO
YES
NO
1750.00
TV40Sa
40
YES
NO
NO
1200.00
TV40
40
NO
NO
NO
950.00
TV32
32
NO
NO
NO
650.00
(a) Give the name of the field that is most suitable to be the primary key.
State the reason for this choice.
Field …
Reason …
…
[2]
(b) The database uses the data types:
•
text
•
character
•
Boolean
•
integer
•
real
•
date/time.
Complete the table to show the most appropriate data type for each field.
Each data type must be different.
Field
Data type
TVCode
ScreenSize
SmartTV
Price$
[2]
(c) Complete the structured query language (SQL) query to return the television (TV) code,
screen size and price of all Smart TVs in the database table.
SELECT TVCode, … , …
… TVRange
WHERE SmartTV = … ;
[4]
Question text
5
The flowchart represents an algorithm.
START
L
0
S
10000
T
0
A
0
INPUT
Limit
Count
1
INPUT
Value
IS
IS
No
No
Value < S
Value > L
?
?
Yes
Yes
L
Value
S
Value
T
T + Value
IS
No
Count >
Count
Count + 1
Limit ?
Yes
T / Limit
A
OUTPUT "L = ", L, " S = ",
S, " T = ", T, " A = ", A
STOP
(a) Complete the trace table for the input data:
10, 30, 18, 8, 25, 12, 17, 2, 50, 15, 5
L
S
T
A
Limit
Count
Value
OUTPUT
[6]
(b) Outline the purpose of the algorithm.
…
…
…
… [2]
(c) Explain why the identifiers L, S, T and A may not be appropriate to use as identifiers and how
they could be improved.
…
…
…
…
…
… [3]
(d) State a more appropriate identifier for each of the variables L, S, T and A
Original identifier
Improved identifier
L
S
T
A
[2]
Question text
5
A database table, APPLIANCE, is used to keep a record of kitchen appliances available for sale.
The following data is stored for each appliance:
•
CATEGORY – washer, dishwasher, fridge or freezer
•
ECONOMYRATING – A, B, C or D
•
MANUFACTURER – Baku or ABC
•
PRICE – price in $
•
CODE – a unique code allocated by the manufacturer e.g. B982
•
STOCK – number in stock.
The database management system uses these data types:
Text
Number
Currency
Boolean
The ECONOMYRATING field and MANUFACTURER field have a data type of text.
(a) Identify the most appropriate data type for each field from the four types shown. State the
reason why you chose each data type.
CATEGORY data type …
Reason …
…
PRICE data type …
Reason …
…
CODE data type …
Reason …
…
STOCK data type …
Reason …
…
[4]
(b) Complete the query-by-example grid to display only the category, manufacturer and code of
the appliances with an economy rating of A.
Field:
Table:
Sort:
Show:
Criteria:
or:
[3]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of