🗄️ Paper 1 · Topic 2: Data & Data Types
2.2c Files & Databases
Edexcel 1CP2 · GCSE Computer Science · ~13 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

Files

A file is a named collection of related data stored on secondary storage (e.g., hard drive, SSD). In programming, files are used to store data persistently — data that survives when the program ends.

  • Text files (.txt, .csv): store data as plain text
  • Binary files: store data in binary format (images, audio, executables)

File Operations in pseudocode:

  • OPEN("file.txt", "r") — open for reading
  • OPEN("file.txt", "w") — open for writing (overwrites)
  • OPEN("file.txt", "a") — open for appending
  • READ(fileHandle, data) — read from file
  • WRITE(fileHandle, data) — write to file
  • CLOSE(fileHandle) — close file
  • EOF(fileHandle) — check if at end of file

Databases

A database is an organised collection of structured data, typically stored in tables. A relational database uses multiple tables linked by relationships.

  • Table: stores records in rows and columns
  • Primary key: a unique field that identifies each record
  • Foreign key: a field in one table that refers to the primary key in another table

Example — School Database

Students tableCourses table
studentID (PK)courseID (PK)
namecourseName
courseID (FK)teacherName

SQL Queries

SQL (Structured Query Language) is used to query and manipulate relational databases:

  • SELECT name, grade FROM Students WHERE grade > 70;
  • SELECT * FROM Students ORDER BY name;
  • INSERT INTO Students VALUES (101, 'Aisha', 85);
  • UPDATE Students SET grade = 90 WHERE studentID = 101;
  • DELETE FROM Students WHERE studentID = 101;

Files vs Databases

FeatureFlat fileDatabase
Data organisationSingle file, no relationshipsMultiple linked tables
SearchingMust read whole fileEfficient queries (SQL)
RedundancyData often duplicatedReduced via normalisation
Multi-userPoorDesigned for concurrent access
Exam tip: Edexcel 1CP2 expects you to know file operations (open, read, write, close, EOF) in pseudocode, understand primary/foreign keys, and write basic SQL queries (SELECT, INSERT, UPDATE, DELETE). Know the advantages of databases over flat files.
⚠️ Common Mistakes
  • Forgetting to close a file after reading/writing
  • Confusing primary key (unique identifier) with foreign key (reference to another table)
  • Not using WHERE in UPDATE/DELETE — this would affect ALL records!
  • Confusing SELECT * (all fields) with SELECT fieldname (specific field)
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — 2.2c Files & Databases

8 Edexcel-style questions · AI-marked

Q1State the purpose of a primary key in a database table.[2]
✅ Mark scheme
A primary key uniquely identifies each record in a table [1]; no two records can have the same primary key value [1].
Q2Write a SQL query to select the names and grades of all students with a grade above 60.[2]
✅ Mark scheme
SELECT name, grade FROM Students WHERE grade > 60; [2] — 1 mark for correct SELECT/FROM, 1 mark for correct WHERE condition.
Q3Explain the difference between a primary key and a foreign key.[2]
✅ Mark scheme
A primary key uniquely identifies each record in its own table [1]; a foreign key is a field in one table that links to the primary key of another table, creating a relationship [1].
Q4State two advantages of using a database over a flat file to store data.[2]
✅ Mark scheme
Any two: efficient queries (SQL) [1]; reduced data redundancy [1]; supports multiple users simultaneously [1]; linked tables allow relationships [1].
Q5In pseudocode, state the operation used to check if all data has been read from a file.[1]
✅ Mark scheme
EOF (End Of File) [1].
Q6Write a SQL command to insert a new student: ID=200, name='Lily', grade=78.[2]
✅ Mark scheme
INSERT INTO Students VALUES (200, 'Lily', 78); [2] — 1 mark for correct syntax, 1 mark for correct values.
Q7Why is it important to close a file after reading from it in a program?[2]
✅ Mark scheme
Closing a file releases system resources [1]; and ensures all data is written/saved properly (flushing buffers) [1].
Q8Explain the difference between opening a file in 'write' mode and 'append' mode.[2]
✅ Mark scheme
Write mode ('w') overwrites any existing content in the file [1]; append mode ('a') adds new data to the end of the file without deleting existing content [1].
Topic Quiz
Q 1 of 15
You scored
out of 15
⚡ XP
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Files & Databases

Timed exam-style test.

← 2.2b Records as DataTopic 2Next: 2.3a Logic Gates →
🔒

Unlock Pro

Subscribe to access all 59 Edexcel 1CP2 lessons.

£7.99/month
or £59/year
Subscribe →