GCSE Computer Science revision
Databases & SQL
Relational databases, tables, keys and queries.
What you will learn
- What is a database?
- Primary and foreign keys
- SQL basics
- Designing a database
- Data types and validation
What is a database?
A database stores data so it can be searched and updated. A relational database organises data into linked tables, avoiding repetition.
- A table holds records (rows) and fields (columns)
- Relational databases link tables
- They reduce data duplication
- A DBMS manages the database
Primary and foreign keys
A primary key uniquely identifies a record. A foreign key links a record in one table to a record in another.
- Primary key: unique identifier for each record
- Foreign key: links to a primary key in another table
- Keys create relationships between tables
- A primary key cannot be empty (null)
SQL basics
SQL (Structured Query Language) reads and changes a database. SELECT reads data; INSERT, UPDATE and DELETE change it.
- SELECT * FROM students
- WHERE filters records
- ORDER BY sorts results
- INSERT, UPDATE and DELETE modify data
Designing a database
Good design splits data into tables by topic, links them with keys, and avoids repeating data (normalisation).
- One table per entity (students, classes)
- Link with foreign keys
- Avoid repeating data
- Normalisation reduces errors and waste
Data types and validation
Each field has a type (text, integer, date). Validation checks that data is sensible before it is stored.
- Field types: text, integer, real, date, Boolean
- Validation: range, presence, format, length
- Verification checks data is entered correctly
- Good data types save space and prevent errors
Worked answers
1. A primary key is…
Answer: A unique identifier for each record
Why: No two records share the same primary key value.
Wrong options to rule out: A type of query; A foreign field; A backup
2. A foreign key is used to…
Answer: Link a record to another table
Why: It references a primary key in another table to form a relationship.
Wrong options to rule out: Encrypt data; Sort records; Delete a table
3. Which SQL command reads data?
Answer: SELECT
Why: SELECT retrieves records that match a query.
Wrong options to rule out: INSERT; DELETE; UPDATE
Practice questions
Answer from memory first. Pick an option to check it and read the explanation.
1. Which SQL clause filters records?
2. Normalisation reduces…
3. Which is a field data type?
4. Presence validation checks…
5. A DBMS is…