0% found this document useful (0 votes)
11 views25 pages

A2 SQL

The document outlines various database design concepts, including the creation of relational databases for a garden furniture company and an insurance company. It discusses the roles of primary and foreign keys, the issues with flat file databases, and the importance of maintaining referential integrity. Additionally, it covers SQL queries, normalization, and the implications of data management in different scenarios.

Uploaded by

thomasobungus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views25 pages

A2 SQL

The document outlines various database design concepts, including the creation of relational databases for a garden furniture company and an insurance company. It discusses the roles of primary and foreign keys, the issues with flat file databases, and the importance of maintaining referential integrity. Additionally, it covers SQL queries, normalization, and the implications of data management in different scenarios.

Uploaded by

thomasobungus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

1 A company sells garden furniture. It has decided to create a relational database.

A first, incomplete database


design includes two tables PRODUCT and ORDER.

PRODUCT (ProductId, ProductType, Size, Price,…)


ORDER (OrderId, OrderDate, ProductId,…)

For example, the product which has ProductId 12345 is a large bench which has a price of £150.

You should use only the data given above.

(i) Explain the use of a primary key in this database.

[2]

(ii) Explain the use of a foreign key in this database.

[4]

© OCR 2024. You may photocopy this page. 1 of 25 Created in ExamBuilder


2(a) An insurance company's offices have a large number of black and white printers.

The company's technicians keep accurate records of the printers in the building, and the quantity of toner
cartridges in stock, in a flat file database. An extract of the database is shown in Fig. 1.

Printer Model Location Notes Cartridge Quantity in Re-order URL


Code stock
LasPrint office 3 LP-7XB 12 www.megacheapprint.com / toner /
LP753 LP-7XB
LasPrint office 6 drum LP-7XB 12 www.megacheapprint.com / toner /
LP710 replaced LP-7XB
Zodiac reception Zod17 4 www.zodiaclaserprinting.com / shop /
ZN217 Z17
Zodiac conference had to add Zod17 4 www.megacheapprint.com / toner /
ZN217 Room 2 RAM LP-7XB
LasPrint office 8 LP-7XB 12 www.megacheapprint.com / toner /
LP753 LP-7XB

Fig. 1

Describe two issues, referring to Fig. 1, that might arise from using a flat file database structure.

[4]

© OCR 2024. You may photocopy this page. 2 of 25 Created in ExamBuilder


(b) A relational database is created with three tables:

PrinterModel: this stores all the data about each model of printer
PrinterInstance: this stores the data about each individual printer in the building
Cartridge: this stores information about the toner cartridges.

Draw an entity-relationship diagram to show the relationships between the three tables.

[4]

3(a) A company sells garden furniture. It has decided to create a relational database. A first, incomplete database
design includes two tables PRODUCT and ORDER.

PRODUCT (ProductId, ProductType, Size, Price,…)


ORDER (OrderId, OrderDate, ProductId,…)

For example, the product which has ProductId 12345 is a large bench which has a price of £150.

A CUSTOMER table is added. An entity-relationship (E-R) diagram is shown.

Explain why this design would be inefficient for customers.

[2]

© OCR 2024. You may photocopy this page. 3 of 25 Created in ExamBuilder


(b) Some of the Structured Query Language (SQL) for this database is

SELECT Surname, Title, PhoneNo


FROM CUSTOMER
WHERE Town = “Coventry”
ORDER BY Surname

Describe the purpose of this code and give one situation in which it may be used.

[5]

4(a) Every bank account has an account number and sort code. The sort code identifies the bank branch (location of
the bank) with which the account is held and the account number uniquely identifies the bank account. An extract
from a bank's database table is shown in Fig. 5.1.

State why the table in Fig. 5.1 is not in Third Normal Form.

[1]

© OCR 2024. You may photocopy this page. 4 of 25 Created in ExamBuilder


(b) Explain how the database could be put into Third Normal Form.

[3]

5(a) A programmer needs to design a database to hold details about customers and their orders for an online
company.

Describe the differences between a flat file and a relational database.

[4]
(b) A database contains three tables labelled Customer, Order and Item. Draw an Entity-Relationship Diagram for
these where a Customer can have many Orders and an Order can have many Items.

[3]

© OCR 2024. You may photocopy this page. 5 of 25 Created in ExamBuilder


6 A database stores information about songs on a music streaming service.

One of the tables called Song has the fields.

A band called RandomBits removes their permission for their songs to be streamed.

The company removes all the songs belonging to RandomBits from their service.

(i) Identify the law with which the company are complying.

[1]

(ii) Write an SQL statement that will remove all songs by RandomBits from the table Song.

[2]

(iii) When the songs have been removed, explain what must happen to the table PlayListEntry if the
database is to retain its referential integrity. (You are not expected to write the SQL to do this).

[1]

© OCR 2024. You may photocopy this page. 6 of 25 Created in ExamBuilder


7 InterMovie is a service that allows users to stream movies over the Internet.

InterMovie has a relational database of the films it offers. The database has the field Film Title which stores the
name of a film (e.g. ‘Aliens Attack’).

(i) Describe why Film Title is not a suitable primary key.

[2]

(ii) Describe why Film Title would make a suitable secondary key.

[2]

8 A company sells garden furniture. It has decided to create a relational database. A first, incomplete database
design includes two tables PRODUCT and ORDER.

PRODUCT (ProductId, ProductType, Size, Price,…)


ORDER (OrderId, OrderDate, ProductId,…)

For example, the product which has ProductId 12345 is a large bench which has a price of £150.

State one additional piece of data which should be included in PRODUCT and give one reason why it is needed.

[2]

© OCR 2024. You may photocopy this page. 7 of 25 Created in ExamBuilder


9(a) A web forum stores all its content in a database.

The forum stores details of its users in the table called Users. An extract of Users is shown below.

userID username passwordHash locked

1 Zeus 8dfa46a79248037752bba6166fcb34f8 1
2 Hera 74d39d60507eb55e000c6ec5c1265891 0
3 Poseidon b015d770d0208ddcce2c2c719fe29371 0

Describe what is meant by the term ‘primary key’, giving an example from the table above.

[2]

© OCR 2024. You may photocopy this page. 8 of 25 Created in ExamBuilder


(b) The user’s password is passed to a function that generates a hash and the result is stored in passwordHash.

(i) Describe what is meant by the term ‘hash’.

[1]

(ii) Describe one advantage to storing the password as a hash.

[2]

© OCR 2024. You may photocopy this page. 9 of 25 Created in ExamBuilder


(c)
Write an SQL statement to get just the passwordHash and locked values of the user Apollo.

[3]
(d)
Sometimes users can have their accounts locked if they behave inappropriately. When this is the case the
locked field is set to 1 rather than 0.

Write an SQL statement that locks the account of the user Hades

[3]

© OCR 2024. You may photocopy this page. 10 of 25 Created in ExamBuilder


(e) The function checkAccess takes in the password the user has entered (givenPassword) along with the
password hash (passwordHash) and locked value (locked).

passwordHash and locked have already been extracted from the database before being passed to the
function. It should return the value true if a user should be allowed access to a system and false if they aren’t.

Your function should make use of the pre-written function hash() which takes in a string and returns the hash
of that string.

e.g.

hash("Hello") returns f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0

Complete the function checkAccess.


function checkAccess (givenPassword, passwordHash, locked)

© OCR 2024. You may photocopy this page. 11 of 25 Created in ExamBuilder


endfunction
[4]

10(a) Explain what the code in Fig. 8.1 does.

[5]

© OCR 2024. You may photocopy this page. 12 of 25 Created in ExamBuilder


(b) In certain scenarios the user's IP address is logged in a database.

(i) Describe what is meant by an IP Address.

[2]

(ii) Explain why the programmers have chosen to store the user's IP address.

[2]

(c) An extract from the database is shown below:

(i) The username admin is entered into the form.

State what the value of statement would be after line 03 of the code in Fig. 8 .1 is run.

[1]

(ii) State what the value of hashInDB would be after line 04 of the code in Fig. 8.1 is run.

[1]

© OCR 2024. You may photocopy this page. 13 of 25 Created in ExamBuilder


(d) In SQL the character ; denotes the next statement and the characters –– denote a comment.

The username DenverJ34'; DROP TABLE users; –– is entered into the form.

(i) State what the value of statement would be after line 03 is run.

[1]

(ii) Describe what happens when line 04 is run.

[2]

(iii) State the name of a law the user has broken by entering the username
DenverJ34'; DROP TABLE users; --

[1]

11(a) A database stores information about songs on a music streaming service.

One of the tables called Song has the fields.

Explain why none of these fields would be suitable as a primary key.

[2]

© OCR 2024. You may photocopy this page. 14 of 25 Created in ExamBuilder


(b) Give one advantage and one disadvantage of indexing the field Artist.

Advantage

Disadvantage

[2]
(c) Users can build up playlists of their songs. Another table is created called Playlist.

Explain why a third table which we shall call PlayListEntry is needed. You should use an ER diagram to
illustrate your answer.

[4]

12(a) The video table consists of the following fields: VideoID, VideoName, Presenter, Topic.

(i) Describe what is meant by the term primary key.

[2]

(ii) Write an SQL query that finds the name and presenter of all videos on the Topic of “The CPU”.

[4]

© OCR 2024. You may photocopy this page. 15 of 25 Created in ExamBuilder


(b) The Big Brains exam board has produced a website that allows students to access revision videos.

All pages in the site contain the following tag in the head section.

The exam board wants to use a database to keep track of which videos each student has viewed. The structure
it plans to use is shown below:

(i) Identify one reason why this structure would not be suitable.

[1]

(ii) Draw a new version of the structure to solve this problem.

[3]

END OF QUESTION PAPER

© OCR 2024. You may photocopy this page. 16 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

1 i Unique identifier 2
ProductId identifies a product / OrderId Examiner's Comments
identifies an order
Most students got the “Unique identifier” as
was expected, a few were able to go on
and say what it was used for. Most
candidates were assumed to have not read
the question correctly.

ii Primary key from one table used as an 4


attribute in another table Examiner's Comments
to link tables / represent relationship
ProductId (is foreign key) in ORDER… A well answered question.
…to show which product has been
ordered

Total 6

2 a Data might be inconsistent…(A01.1) 4


… For example the amount of LP-7XB Examiner's Comments
toner cartridges might be reduced in
one record but not in other records. Many candidates achieved some marks on
(A02.2) this question. However some did not use
the terminology expected at this level of
Space is wasted through redundant study e.g. data redundancy; data
data… (A01.1) inconsistency.
… For example the Re-order URL for
each toner cartridge is stored multiple
times. (A02.2)

b Entities and relationships drawn using 4


standard notation. (AO1.1)
Cartridge linked to PrinterModel,
PrinterModel linked to PrinterInstance
with no other links. (AO 2.1)
1:M relationship from Cartridge to
Printer Model (AO 2.1) Examiner's Comments
1:M relationship from PrinterModel to
PrinterInstance. (AO 2.1) Few candidates scored full marks on this
question. Candidates invariably associated
the ‘cartridge’ entity directly with the ‘printer
instance’ entity, not gaining credit. Many
diagrams had no indication of the degree
of relationship between entities, again not
gaining credit.

Total 8

© OCR 2024. You may photocopy this page. 17 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

3 a Only one product can be on an order 2


Customer would have to make a Examiner's Comments
separate order for each product
required A few candidates showed a lack of
understanding of the E-R Diagram and
said that customers would not be able to
see the products, but most were able to
correctly analyse what was asked for.

b Lists attributes Surname, Title, 5 Accept other relevant purposes


PhoneNo
from the table CUSTOMER
for all customers in Coventry
in ascending order of Surname Allow A - Z / alphabetical
e.g. for local promotions / new store
opening Examiner's Comments

Another question that was targeted at


precise technical language, it was clear
from the candidates responses that some
only had very superficial knowledge of this
topic.

Total 7

4 a Branch name depends on Sort Code (i.e. 1


there is a transitive relationship).

b Create another table for Branches which 3


should include sort-code and branch name.
(1) Make sort code the primary key of the
BRANCH table/ Add a primary key to
BRANCH. (1) Remove Branch name from
Customers, leave sortcode as primary key/
Remove sort-code and branch name from
customers and add the primary key values
from BRANCS as the foreign key (1)

ALTERNATIVE ANSWER (ER-DIAGRAM)


Two tables CUSTOMER and BRANCH (or
similar names) (1)
Link from CUSTOMER to BRANCHES is
Many (1) to One (1)

Total 4

© OCR 2024. You may photocopy this page. 18 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

5 a Flat file 4

May have redundant data


Flat file harder to update
No specialist knowledge needed to
operate
Allow for opposites eg RD has no repeated
Relational database data. Only one mark per bullet

Examiner's Comments
Data Integrity
Linked tables Mostly well answered
Easier to change format
Provides security features

b Correct names 3
1 to many between Customer and
Order
1 to many between Order and Item CAO

Examiner's Comments

As was expected most candidates got the


full three marks on this. The most common
mistake was not using proper names;
candidates seemed to feel the need to
make everything plural.

Total 7

6 i Copyright, Design and Patents Act 1 Accept Copyright Act / Law

ii 2
(1
mark per –, max 2)

iii All entries in which 1


contain songs by RandomBits must be
removed.

Total 4

© OCR 2024. You may photocopy this page. 19 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

7 i A primary key must have a unique 2 One mark (AO 1.2) for identification of
value for each record (1 – AO1.2) - appropriate reason.
however it is possible for two films to
have the same name (1 – AO2.1). One mark (AO 2.1) for applying knowledge
to given context.

ii A secondary key is indexed allowing 2 One mark (AO 1.2) for identification of
for faster searching (1 – AO1.2) and appropriate reason.
users are likely to want to search by
film (1 – AO2.1). One mark (AO 2.1) for applying knowledge
to given context.

Total 4

8 e.g. 2 Marks for single example with reason only

NoInStock…
…to check stock levels / allow re- Accept other relevant examples
ordering
Location (in warehouse)… Examiner's Comments
…to find item when needed
A very open ended question that was
designed to test candidates' ability to
hypothesise about what should be in a
database, most candidates achieved a
creditable answer.

Total 2

© OCR 2024. You may photocopy this page. 20 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

9 a A field which has a unique value for every 2


record / A unique identifier. (1)
(AO1.1 –

E.g. userID (1) 1, AO2.1


-1)

Examiner’s Comments
Well received and answered by most
candidates.

b i A result generated by applying an 1


algorithm / numeric process to a value. (1)
(AO1.1)

ii Hash functions are one way / can’t 2


be reverse (1)

If someone gains access to the (AO1.2 1


database they cannot access user’s mark,
password. (1) Examiner’s Comments
AO2.1 Many candidates achieved the mark in
part i) few achieved both marks in part ii)
1 mark) mostly stating as opposed to describing the
advantage e.g. ‘those who gain
unauthorised access cannot access
passwords’ without going on to say ‘hash
functions are one way’.

c SELECT passwordHash, locked (1) 3 Do not award first mark for SELECT *
FROM Users (1)
WHERE username=‘Apollo’ (1) (AO 3.2)

Examiner’s Comments
In most cases, candidates who achieved
marks in c) went on to achieve marks in d)
with few candidates achieving all marks in
either. Many candidates did not use correct
SQL statement structure or syntax e.g.
confusing attribute names with string
literals.

© OCR 2024. You may photocopy this page. 21 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

d UPDATE Users (1) 3 Allow other updating method


SET locked=1 (1) e.g. a DELETE statement followed by an
INSERT statement, for full marks e.g.
(AO 3.2)
WHERE username=‘Hades’ (1)

Examiner’s Comments
In most cases, candidates who achieved
marks in c) went on to achieve marks in d)
with few candidates achieving all marks in
either. Many candidates did not use correct
SQL statement structure or syntax e.g.
confusing attribute names with string
literals.

e Takes a hash of givenPassword 4 Example code:


(NB this may be done inline e.g.
if hash (givenPassword)==pa (AO 3.2)
sswordHash and locked==0
then (1)

Returns true if password is correct


and account is unlocked. (1) Candidates may have taken a different
approach - any solution that fulfils the
Returns false if account is locked (1) criteria on the left should get them marks.

Returns false if password is


incorrect (1)
Examiner’s Comments
Candidates were asked to complete a
function in this question. Although many
students demonstrated reasonable logic in
solving this problem, some used output
statements rather than returned values
from the function, therefore, not gaining full
marks.

Total 15

© OCR 2024. You may photocopy this page. 22 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

10 a Any five from: 5


Takes the username and password from
the form (1)
Uses the username to create an SQL
statement (1) to get the passwordHash
belonging to the given username (1) Runs
the SQL Statement (1) hashes the given
password and compares it to the retrieved
hash (1)
If they match it generates a success
webpage, otherwise it records the user’s IP
address. (1)

b i Any two from: 2


A numerical address made of 4 numbers
each between 0 and 255 / 32 hexadecimal
digits (1)
That uniquely identifies a device on a
network. (1)
It is a logical identifier (i.e. can change on a
physical device) (1)

ii IP address can help identify a user… (1) 2


…so company can potentially track users
attempting to gain unauthorised access (1)

c i SELECT passwordHash FROM users 1


WHERE name = ‘admin’

ii 0e5a511 1

d i SELECT passwordHash FROM users 1


WHERE name = ‘DenverJ34’; DROP
TABLE users; ’ --

ii Gets passwordHash for username 2


DenverJ34 (1)
then deletes the table called users. (1)

iii Computer Misuse Act 1

Total 15

© OCR 2024. You may photocopy this page. 23 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

11 a – A primary key must have a unique 2


value for every record
– The values for all these fields could
repeat.
(1 per –)

b – Advantage: Searches of Artist can be 2


performed more quickly.
– Disadvantage: The index takes up
extra space in the database.
(1 per –)

c – would have a 4
many to many relationship
– This is not allowed
– Adding a table between them resolves
this
– Diagram to illustrate this.

(1 per –)

Total 8

© OCR 2024. You may photocopy this page. 24 of 25 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

12 a i A field that has a unique value / a 2 Up to 2 marks for a valid description.


unique identifier (1) for every record in
that table (1) – in this case VideoID (1).

ii SELECT VideoName, Presenter (1) 4 For 4 marks.


FROM Video (1) WHERE Topic (1)
=“The CPU” (1). Do not award first mark if any other field or
SELECT *

SELECT VideoName, Presenter FROM


Video WHERE Topic=“The CPU”

b i Many to Many relationships are not 1 For 1 mark.


allowed / in 3NF (1).

ii Table added between student and 3 For 3 marks.


video (1).
Student to middle table 1:M
relationship (1).
Middle table to video M:1 relationship
(1).

Total 10

© OCR 2024. You may photocopy this page. 25 of 25 Created in ExamBuilder

Powered by TCPDF (www.tcpdf.org)

You might also like