How do you store and work with lists and tables of data, and query records with SQL?
Using one-dimensional and two-dimensional arrays, the use of records to store structured data, and basic SQL (SELECT, FROM, WHERE) to search records in a database.
An OCR J277 2.2.3 answer on storing structured data: one-dimensional and two-dimensional arrays, records, and using basic SQL (SELECT, FROM, WHERE) to search records in a database table.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
OCR wants you to store and work with structured data: one-dimensional and two-dimensional arrays, records, and basic SQL (SELECT, FROM, WHERE) to search records in a database. You must read and write array elements by index, understand a 2D array as a table, and write simple queries. This is examined in Paper 2, including Section B.
One-dimensional arrays
A loop over an array uses the index as the loop counter:
total = 0
for i = 0 to 4
total = total + scores[i]
next i
print(total)
Two-dimensional arrays
Records
SQL: searching records
Try this
Q1. For the array data = [5, 10, 15, 20], state the value of data[1]. [1 mark]
- Cue. 10 (index 1 is the second element, because arrays start at index 0).
Q2. State what the SELECT and WHERE clauses of an SQL query do. [2 marks]
- Cue. SELECT lists the fields to return; WHERE gives a condition that filters which records (rows) are returned.
Q3. Write an SQL query to return all fields of the Books table where the Author is "Orwell". [2 marks]
- Cue.
SELECT * FROM Books WHERE Author = "Orwell".
Exam-style practice questions
Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
OCR 20214 marksA one-dimensional array called scores holds the values [12, 8, 15, 4, 9]. State the value of scores[2], and write an algorithm that prints the largest value in the array.Show worked answer →
Value (1 mark): arrays are 0-indexed in the OCR Exam Reference Language, so scores[0] is 12, scores[1] is 8, and scores[2] is 15.
Algorithm (up to 3): set a variable to the first element, then loop through the rest, updating it whenever a larger value is found.
largest = scores[0]
for i = 1 to 4
if scores[i] > largest then
largest = scores[i]
endif
next i
print(largest)
Marks: initialise largest to the first element (1), loop through the array (1), compare and update correctly then output (1). The most common error is forgetting arrays start at index 0, giving scores[2] as 8.
OCR 20223 marksA database table called Students has the fields StudentID, Name, Year and Tutor. Write an SQL query to return the Name and Tutor of every student in Year 11.Show worked answer →
The query selects the two named fields from the table where the Year is 11:
SELECT Name, Tutor
FROM Students
WHERE Year = 11
Marks: correct SELECT with the two fields (1), correct FROM with the table name (1), correct WHERE condition Year = 11 (1).
Markers reward the three clauses in the right form. Using SELECT * returns all fields, which does not match "Name and Tutor", so it would lose the SELECT mark. SQL uses a single = in WHERE, not ==.
Related dot points
- The use of variables and constants, the common data types (integer, real, Boolean, character and string), choosing an appropriate data type, and casting (converting) between data types.
An OCR J277 2.2.1 answer on variables and constants, the common data types (integer, real, Boolean, character, string), choosing an appropriate data type for data, and casting between data types.
- String manipulation (length, position, substring, concatenation and changing case, and converting between characters and character codes) and basic file handling (opening, reading, writing and closing text files).
An OCR J277 2.2.3 answer on string manipulation (length, substring, concatenation, case change, character codes with ASC and CHR) and basic file handling (opening, reading, writing and closing text files) in the OCR Exam Reference Language.
- The use of subprograms (procedures and functions), passing parameters into a subprogram, returning values from a function, local versus global variable scope, and generating random numbers.
An OCR J277 2.2.3 answer on subprograms: procedures and functions, passing parameters, returning values, the difference between local and global variables, the benefits of subprograms, and generating random numbers.
- Standard searching algorithms: linear search and binary search, how each works step by step, the requirement that binary search needs a sorted list, and the comparison of their efficiency.
An OCR J277 2.1.3 answer on the two standard searching algorithms: how linear search and binary search work step by step, why binary search needs a sorted list, and how their efficiency compares.
- Standard sorting algorithms: bubble sort, insertion sort and merge sort, how each works step by step, and how they compare in approach and efficiency.
An OCR J277 2.1.3 answer on the three standard sorting algorithms: how bubble sort, insertion sort and merge sort each put a list in order step by step, and how they compare in method and efficiency.
Sources & how we know this
- OCR GCSE (9-1) Computer Science (J277) specification — OCR (2020)