← 💻 Computer Science

Cambridge IGCSE 0478 · Topic 9 of 10

Databases

Single-table databases: fields, records, data types and primary keys, and using SQL to search, sort and total data.

📌 Key points

  1. A database is a structured collection of data. A single-table database is made of records (rows, one per item, e.g. one student) and fields (columns, one per piece of data, e.g. Name).
  2. Each field has a data type: text/alphanumeric, character, Boolean, integer, real or date/time.
  3. A primary key is a field that uniquely identifies each record, so its values can never be repeated, e.g. StudentID.
  4. Validation rules can be set on fields (e.g. range, presence, length, format) to reduce data entry errors.
  5. SQL (Structured Query Language) is used to search a database: SELECT lists the fields to show, FROM names the table, WHERE gives the search condition.
  6. ORDER BY sorts the results by a field, in ascending order unless DESC is added for descending order.
  7. AND means both conditions must be true; OR means at least one condition must be true.
  8. SUM(Field) adds up the values in a numeric field and COUNT(*) counts the records that match the query.

📖 Key terms

Field
One item of data stored about every record, shown as a column, e.g. Surname.
Record
All the data about one item or person, shown as a row.
Primary key
A field that uniquely identifies each record in a table.
SQL
Structured Query Language, used to search and manage data in a database.
Query
A request to search a database for records that meet given conditions.
Data type
Defines the kind of data a field can hold, e.g. integer, real, Boolean.

✏️ Worked example

Table Students has fields ID, Name, Form, Age. Write SQL to show the Name and Age of every student in form 10A, sorted by Name.

  1. Choose the fields to display: SELECT Name, Age
  2. Name the table: FROM Students
  3. Add the condition: WHERE Form = '10A'
  4. Sort the results: ORDER BY Name;
  5. Full query: SELECT Name, Age FROM Students WHERE Form = '10A' ORDER BY Name;
💡 Exam tip

Only list the fields the question asks you to display in SELECT. A field can be used in WHERE or ORDER BY without being shown, and adding extra fields can lose the mark.

Test yourself8 questions from a bank of 14. A new mix every time.
Start the quiz →

It’s bedtime! 😴

It’s late, and even Numo is getting sleepy. The best thing you can do for your learning now is… go to sleep!

✨ Sleep helps you

  • 🧠 remember what you learned today: your brain saves it while you sleep
  • 🌱 grow and stay healthy
  • ⚡ wake up with energy, ready to learn and play
  • 😊 feel happy and calm

🦉 Going to bed late can make you

  • 😩 tired and sleepy at school tomorrow
  • 🤯 find it harder to focus and to remember
  • 😠 grumpy and easily upset
  • 🤧 catch colds more easily

Children your age need 9 to 12 hours of sleep every night. Numo will be right here tomorrow!