Database Past Paper With SQL
Database Past Paper With SQL
Database Past Paper With SQL
....................................................................................................................................[1]
(b) State which field you would choose for the primary key.
......................................................................................................................................
......................................................................................................................................
..................................................................................................................................[2]
(c) State the data type you would choose for each of the following fields.
Garage..........................................................................................................................
Number of Bedrooms… … … … … … . . . … … … … … … … … … … … … … … … … …
Price in $..................................................................................................................[3]
Page 1 of 37
(d) Write a SQL code to show all houses with more than 1 bathroom and more than 2 bedrooms
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
…………………………………………………………………..……………………………………………….
................................................................................................................................... [2]
(e) Write a SQL code to select and show the brochure number, property type and price of all
properties with a garage below $200,000.
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
………………………………………………………………………………………………………………[4]
2210/22/M/J/15
2. A database, MARKS, was set up to record the test results for a class of students. Part of the
database is shown below.
....................................................................................................................................[1]
(b) State which field you would choose for the primary key.
Page 2 of 37
......................................................................................................................................
........................................................................................................................................
....................................................................................................................................[2]
(c) Write a SQL code to show all student’s name in ascending order with more than 60 marks in History
or more than 60 marks in Geography.
Show what would be output.
........................................................................................................................................
....................................................................................................................................[2]
(d) Write a SQL code to select and show the student names only of all students with less than 40
marks in both Maths and English.
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
2210/22/O/N/15
3. A picture gallery owner has decided to set up a database to keep information about the pictures he
has for sale. The database table, PICTURE, will contain the following fields:
Title; Artist; Description; Catalogue Number; Size (area in square centimetres); Price; Arrived (date picture
arrived at gallery); Sold (whether picture is already sold)
(a) (i) State what data type you would choose for each field.
Title.........................................................................................................................
Artist.......................................................................................................................
Description….........................................................................................................
Catalogue Number..................................................................................................
Size...................................................................................................................................................
Price .....................................................................................................................
Arrived....................................................................................................................
Page 3 of 37
Sold....................................................................................................................[4]
(ii) State which field you would choose for the primary key.
..........................................................................................................................[1]
(b) Give a validation check that you can perform on each of these fields. Each validation check must
be different.
CatalogueNumber........................................................................................................
Size................................................................................................................................
Price...............................................................................................................................
Arrived.......................................................................................................................[4]
(c) Write a SQL code to select and show the Catalogue Number, Title and Price of all unsold
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………..
2210/23/O/N/15
4. A motor boat hire company decides to set up a database to keep information about boats that are
available for hire. The database table, BOAT, will contain the following fields:
Boat Name; Model; Engine Power (in hp); Number of Seats; Life Raft (whether there is a life raft kept
on the boat); Day Price (price for a day’s hire).
(a) Give the data type you would choose for each field.
Model ............................................................................................................................
Page 4 of 37
Life Raft ........................................................................................................................
(b) State a validation check that you can perform on each of these fields. Each validation check must
be different.
Model ............................................................................................................................
(c) Write a SQL code to select and show the Boat Name, Model and Day Price of a day’s hire for all boats
with 4 seats and an Engine Power of more than 100hp.
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
2210/22/M/J/16
6. A database, SOFASELECT, was set up to show the prices of suites, sofas and chairs for sale from an online
furniture warehouse. Part of the database is shown below.
Page 5 of 37
(b) State which field you would choose for the primary key.
.................................................................................................................................................
.............................................................................................................................................
...............................................................................................................................................[2]
(c) State the data type you would choose for each of the following fields.
Price in $ ..............................................................................................................................[2]
(a) The query-by-example grid below selects all the furniture in cream leather.
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
...................................................................................................................................................
...............................................................................................................................................[3]
(b) Write a SQL code to select and show the brochure number, material, colour and price of all the
furniture with 3 or more seats.
………………………………………………………………………………………………………………………
Page 6 of 37
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
2210/22/O/N/16
7. A database, PLAYPRODUCTION, was set up to show the performance dates, prices and number of seats
available at a theatre specializing in Shakespeare productions.
....................................................................................................................................................... [1]
(b) State the data type you would choose for each of the following fields.
Play .....................................................................................................................................................
Page 7 of 37
Number Seats Stalls ............................................................................................................................
(c) The query-by-example grid below selects all the productions with more than 100 seats left in either the
stalls or the circle.
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
..........................................................................................................................................................................
..........................................................................................................................................................................
..................................................................................................................................................................... [3]
(d) Write a SQL code to select all the productions with at least six seats left in the circle and show the Play,
Performance Date and Price Circle Seats $ in Performance Date order.
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………[4]
Page 8 of 37
2210/23/O/N/16
8. A database, THEATRETOURS, was set up to show the tour dates, towns, number of seats and prices in
local currency for a Shakespeare play.
(a) Explain why none of the fields in the database can be used as a primary key.
.....................................................................................................................................................................
.....................................................................................................................................................................
..............................................................................................................................................................[2]
...................................................................................................................................................................
Give a reason for choosing this field.
.....................................................................................................................................................................
...............................................................................................................................................................[2]
(c) Write SQL code to provide a list of tour dates and seat prices in alphabetical order of town.
……………………………………………………………………………………………………………………………
Page 9 of 37
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………[4]
2210/21/M/J/17
9. A television (TV) store has a database table, TVSTOCK, for its new range of televisions. The table stores the screen size
of each TV, whether it will show 3D, whether the screen is curved or flat, if the internet is available on the TV, if it has a
built-in hard disk drive and the price. Part of the database table is shown below.
(a) State the type of the field TVID and give a reason for your choice.
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[1]
(b) Complete the table with the most appropriate data type for each field
Page 10 of 37
(c) Use the query-by-example grid below to provide a list of all of the curved screen TVs that have a built-in hard
disk drive. Make sure the list only displays the TVID, the price and the screen size in ascending order of price.
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………[4]
2210/22/M/J/17
10. A database table, SHEEP, is used to keep a record of the sheep on a farm. Each sheep has a unique ear tag,
EARnnnn; n is a single digit. The farmer keeps a record of the date of birth, the gender and the current weight of each
sheep in kilograms.
(a) Identify the four fields required for the database. Give each field a suitable name and data type. Provide a sample of
data that you could expect to see in the field.
(b) State the field that you would choose as the primary key.
Page 11 of 37
…........................................................................................................................................................[1]
(c) Write SQL code to identify the ear tags of all male sheep weighing over 10 kilograms. Only display the ear tags.
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
2210/22/O/N/17
11. A database table, TRAIN, is to be set up for a railway company to keep a record of the engines available for use. Each
engine has a unique number made up of 5 digits, nnnnn. The engines are classified as freight (F) or passenger (P)
together with a power classification that is a whole number between 0 and 9, for example F8. The railway company
keeps a record of the date of the last service for each engine.
(a) Identify the three fields required for the database. Give each field a suitable name and data type. Provide a sample
of data that you could expect to see in the field.
(b) State the field that you should choose as the primary key.
...................................................................................................................................................[1]
(c) Write SQL code to to identify all passenger engines that have not been serviced in the past 12 months. Only
display the engine numbers.
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
Page 12 of 37
……………………………………………………………………………………………………………………………
2210/23/O/N/17
12. A wildlife park has a database table, called LIVESTOCK, to classify and record its animal species. Part of the database
table is shown.
(a) Write SQL code to provide a list of all four legged mammals that are herbivores, sorted alphabetically by
species, with only the species displayed.
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………[4]
2210/21/M/J/18
13. A database table, PERFORMANCE, is used to keep a record of the performances at a local theatre.
Page 13 of 37
(a) State the number of fields and records in the table.
Fields ........................................................................................................................................
Records .................................................................................................................................... [2]
(b) Give two validation checks that could be performed on the Show Number field.
Validation check 1 .....................................................................................................................
...................................................................................................................................................
Validation check 2 .....................................................................................................................
................................................................................................................................................... [2]
(c) Write SQL code to identify jazz performances that are not sold out. Only display the date and the title.
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………[4]
2210/22/M/J/18
14. A database table, TREES, is used to keep a record of the trees in a park. Each tree is given a unique number and is
examined to see if it is at risk of dying. There are over 900 trees; part of the database table is shown.
Page 14 of 37
State the number of fields in the table.
..............................................................................................................................................................................[1]
(a) The tree numbering system uses TN followed by three digits. The numbering system will not work if there are
over 1000 trees.
Describe, with the aid of an example, how you could change the tree numbering system to allow for over 1000
trees. Existing tree numbers must not be changed.
.....................................................................................................................................................................................
.....................................................................................................................................................................................
.....................................................................................................................................................................................
................................................................................................................................................................................[2]
(b) write a SQL code to identify at risk trees over 100 years old. Display only the type and the position on the map.
.....................................................................................................................................................................................
.....................................................................................................................................................................................
.....................................................................................................................................................................................
................................................................................................................................................................................[2]
2210/22/O/N/18
15. A database table, PORTRAIT, is used to keep a record of the portraits available from a photographic studio. Each
portrait has a unique reference number PICnnn, where n is a single digit, for example PIC123. The studio keeps a record
of the size (for example 20 × 15), the type (black and white or colour), and the price in dollars.
(a) Complete the table to show the most appropriate data type for each of the fields.
Page 15 of 37
(b) write a SQL code to show the reference number, price, type and size of all portraits under $50. Identify the three
errors in the query-by-example grid.
(c) ........................................................................................................................................................................
........................................................................................................................................................................
........................................................................................................................................................................
...................................................................................................................................................................[2]
2210/23/O/N/18
16. An online fruit tree specialist sells fruit trees in various sizes. A database table, TREETAB, shows the tree type and, for
each size, the price and whether they are in stock.
(a) State whether any of the fields shown would be suitable as a primary key.
...................................................................................................................................................
Page 16 of 37
Explain your answer .................................................................................................................
...................................................................................................................................................
................................................................................................................................................... [2]
(b) Complete the table to show the most appropriate data type for each of the fields based on the data shown in
the table at the start of question 6.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
(d) Write the SQL code for the to identify all types of the fruit trees that are out of stock for all three sizes. Make
sure the type of the tree and the various ‘in stock’ fields are shown. The trees should be listed in alphabetical
order by type.
Page 17 of 37
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
2210/21/M/J/19
17. The table, BEVERAGES, shows the number of calories in 100ml of a range of popular beverages. It also shows the
availability of these drinks in a can, a small bottle and a large bottle.
(a) Give a reason for choosing BevNo as the primary key for this table.
...................................................................................................................................................
............................................................................................................................................. [1]
............................................................................................................................................. [1]
Page 18 of 37
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(d) Write the SQL code to output a list showing just the names and primary keys of all the beverages with a calorie
count greater than 45. The list should be in alphabetical order of names.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
2210/22/M/J/19
18. A database table, FLIGHT, is used to keep a record of flights from a small airfield. Planes can carry passengers, freight
or both. Some flights are marked as private and only carry passengers.
Page 19 of 37
(a) State the field that could have a Boolean data type. Field
.................................................................................................................................... [1]
Write the SQL code to display just the flight numbers of all planes leaving after 10:00 that only carry passengers.
..................................................................................................................................................................................................
..................................................................................................................................................................................................
..................................................................................................................................................................................................
............................................................................................................................................................................................[3]
2210/22/O/N/19
19. A database table, SALES, is used to keep a record of items made and sold by a furniture maker.
Page 20 of 37
(a) Explain why the field Item number could not be used as a primary key.
...................................................................................................................................................
................................................................................................................................................... [1]
(b) Write the SQL code to display only the order number and item numbers of any items in progress or not
started.
..................................................................................................................................................................................................
..................................................................................................................................................................................................
..................................................................................................................................................................................................
..............................................................................................................................................................................................[4]
2210/23/O/N/19
20. 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.
(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) Write the SQL code 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.
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………….[4]
2210/21/M/J/20
Page 21 of 37
21. A garden centre sells garden tools and stores details of these in a database table named TOOLS. Code is the primary
key in the TOOLS table.
(a) State the purpose of the primary key in the TOOLS table.
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [1]
(b) Write the SQL code to output the tools where the quantity in stock is below 25. Only show the Code,
Description and Quantity_Stock fields in ascending order of Code.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
2210/22/M/J/20
Page 22 of 37
21. A database table, JUICE, is used to keep a record of cartons of fresh fruit juice available for sale.
(a) Identify a suitable field to use as the primary key. State a reason for your choice.
Field ..........................................................................................................................................
Reason ......................................................................................................................................
................................................................................................................................................... [2]
(b) Write the SQL code to display only the stock level and size of all cartons containing only apple juice.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
2210/22/O/N/20
22. The table AUDIOPARTS stores the part number, description, cost and quantity in stock of the items sold by a music
shop.
Page 23 of 37
(a) State the number of records in the table AUDIOPARTS
............................................................................................................................................. [1]
(b) Identify the field that is most suitable to be a primary key and give a reason for your choice.
Fieldname .................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
................................................................................................................................................... [2]
(c) Write the SQL code to display the items where the quantity in stock is fewer than 10. Show all the fields
from the database table in descending order of cost.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]10/23/O/N/20
23. A marine wildlife rescue centre uses a database table, MARINE, to keep records of its creatures.
Page 24 of 37
(a) State how many fields and how many records are shown in this table.
(b) Write the SQL code to display the creatures, in ascending order of quantity, that have no offspring and are
ready for release. Display only the creature field.
(c) ...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
2210/21/M/J/21
24. A library uses a database table, GENRE, to keep a record of the number of books it has in each genre.
Page 25 of 37
(a) State the reason ID could be used as a primary key in the table GENRE.
...................................................................................................................................................
............................................................................................................................................. [1]
...................................................................................................................................................
............................................................................................................................................. [1]
(c) Write the SQL code to display to display any genres with overdue books. Only display the ID, GenreName
and Overdue fields in order of the number of books overdue from largest to smallest.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
2210/22/M/J/21
25. A database table, PLANT, is used to keep a record of plants sold by a nursery. The table has these fields:
A query-by-example grid has been completed to display only the price, name and number sold of small plants
Page 26 of 37
identify the errors in the folloing SQL code.
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………………………………[4]
2210/22/O/N/21
26. A pet supplier uses the database table, STOCK, to keep records of its products for pets. The fields are:
(a) (i) Identify the field that could have a Boolean data type.
..................................................................................................................................... [1]
(ii) Identify the field that should be used as the primary key.
..................................................................................................................................... [1]
(b) Write the SQL code to display to output the products intended for a cat that are in stock. Display only the
primary key and the name of the products. The output should be sorted by the primary key.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Page 27 of 37
...................................................................................................................................................
............................................................................................................................................. [4]
2210/21/M/J/23
Page 28 of 37
2210/22/M/J/23
10 A music streaming service has a new database table named Songs to store details of songs
available for streaming. The table contains the fields:
• SongNumber – the catalogue number, for example AG123
• Title – the title of the song
• Author – the name of the song writer(s)
• Singer – the name of the singer(s)
• Genre – the type of music, for example rock
• Minutes – the length of the song in minutes, for example 3.75
Page 29 of 37
• Recorded – the date the song was recorded.
(a) Identify the field that will be the most appropriate primary key for this table.
............................................................................................................................................. [1]
(b) Complete the table to identify the most appropriate data type for the fields in Songs
SongNumber
Title
Recorded
Minutes
[2]
(c) Explain the purpose of the structured query language (SQL) statements.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
2210/22/O/N/23
2 A database table called Horses stores details about the horses kept at a horse sanctuary.
Page 30 of 37
H010 Friesian Netherlands M 6 15/11/20
22
H011 Fjord Norway F 4 17/11/20
22
H012 Clydesdale Scotland M 10 18/11/20
22
H015 Arabian Saudi Arabia F 5 15/12/20
22
H016 Arabian Saudi Arabia F 5 15/12/20
22
H017 Clydesdale Scotland F 4 16/01/20
23
H019 Percheron France M 3 16/01/20
23
H025 Percheron France M 7 16/01/20
23
H026 Clydesdale Scotland F 9 20/01/20
23
H030 Clydesdale Scotland M 12 20/01/20
23
H032 Fjord Norway M 3 24/03/20
23
H033 Arabian Saudi Arabia F 15 27/04/20
23
H034 Clydesdale Scotland F 4 14/06/20
23
H035 Fjord Norway M 7 15/06/20
23
H036 Friesian Netherlands F 15 20/07/20
23
H037 Friesian Netherlands M 12 20/07/20
23
............................................................................................................................................. [1]
(b) Give the name of the field that is most suitable to be the primary key.
Field ..........................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
[2]
(a) The database only allows the data types:
• Boolean
Page 31 of 37
• character
• date/time
• integer
• real
• text.
Complete the table to show the most appropriate data type for each field.
Each data type must be different.
Gender
Age
Arrived
[2]
(b) Complete the structured query language (SQL) to return the code and breed of all the horseswhose
breed originated in Scotland.
FROM .........................................
Page 32 of 37
9.A sanctuary for pheasants has set up a new database table called PheasantList to store details
of the different species of bird at the sanctuary. Part of this table is given, showing: species,
description, number of birds at the sanctuary, if the birds are breeding or not, and number of
young born this year.
Page 33 of 37
Page 34 of 37
9 A shop that sells books has set up a new database table called BookList to store book details.
Part of this table is given.
(a) State the number of records in this part of the database table.
............................................................................................................................................. [1]
(b) (i) Give the name of the field that would be used for the primary key.
..................................................................................................................................... [1]
(ii) State the reason for choosing this field for the primary key.
...........................................................................................................................................
..................................................................................................................................... [1]
Page 35 of 37
(c) Complete the table to identify the most appropriate data type for each field based on the data
CatNo
Title
Fiction
Price
[2]
(d) Write the output from this structured query language (SQL) statement.
FROM BookList
WHERE StockLevel = 0;
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(e) Complete this SQL statement to display all the titles by the author B Penn.
SELECT .....................................................................................................................................
FROM .........................................................................................................................................
WHERE ...................................................................................................................................[2]
0478/22/F/M/24
9 A storage unit rental company wants to set up a new database table for the storage units that can
be rented. The table is called StorageUnits and needs to store these details:
Page 36 of 37
• PriceMonth – the price in dollars for a month’s rental
• StorageID – the code to identify each storage unit, for example S123
(a) (i) Give the name of the field that would be used for the primary key.
..................................................................................................................................... [1]
(ii) State the reason for choosing this field for the primary key.
...........................................................................................................................................
..................................................................................................................................... [1]
(b) Complete the table to identify the most appropriate data type for these fields in the table
StorageUnits
SizeMetres
Position
Hoist
StorageID
[2]
(c) Complete this structured query language (SQL) statement to display only the storage code,
price and size in square metres of all the storage units where there is a hoist available.
SELECT ....................................................................................................................................
FROM ........................................................................................................................................
Page 37 of 37