Databases and big data · A level · OCR H446 1.3.2, AQA 7517 4.10.2, Eduqas A500QS 2.4 · about 55 min
Flat files against relational databases, and every kind of key: primary, composite, foreign and secondary, with indexes and how records are found.
[1 mark]What is a composite primary key?
[1 mark]Which describes a secondary key?
[1 mark]Which are disadvantages of a flat file database compared with a relational database?
Tick every answer that is true.
[1 mark]Adding an index on the task field of a runs table will usually...
[1 mark]Records are stored at an address calculated from their key. Which file organisation is this?
[1 mark]What does this print?
SLOTS = 7
table = [None] * SLOTS
for key in [9, 16, 4]:
address = key % SLOTS
while table[address] is not None:
address = (address + 1) % SLOTS
table[address] = key
print(table)A robot may make several attempts at a task, numbered from 1 for each robot. The list attempts holds records (robot_id, attempt, cm): two whole numbers and a float.
1. Create a table attempts with the fields robot_id, attempt and cm, and the composite primary key (robot_id, attempt).
2. Insert every record, in order. For each one print added robot <robot_id> attempt <attempt>, or, if the database refuses it with sqlite3.IntegrityError, print rejected robot <robot_id> attempt <attempt>: already logged.
3. Use SELECT COUNT(*) to print the number of records now in the table as records: <n>.
Seven lines in all. The robot does not move.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
import sqlite3
attempts = [(1, 1, 42.0), (1, 2, 45.5), (2, 1, 38.0), (1, 2, 44.0), (3, 1, 76.5), (2, 1, 39.0)]
db = sqlite3.connect(":memory:")Plan your program here, then type it in and press Run.
SELECT by task with and without an index. How big must the table be before the index shows?