Databases (Copy)
IGCSE / O Level Computer Science Cheat Sheet
Topic: 9 – Databases
🗃️ What is a Database?
- A structured collection of data stored in tables consisting of fields (columns) and records (rows)
- Supports efficient storage, retrieval, and management of data
🔑 Key Database Terms
| Term | Description |
|---|---|
| Field | Column in a table (e.g. Name, Age) |
| Record | Row in a table (e.g. one person’s data) |
| Table | Set of related records |
| Primary Key | Unique identifier for each record |
| Validation | Ensures data entered is sensible and accurate |
🔣 Data Types
| Data Type | Description | Example |
|---|---|---|
| Text/String | Letters, words, numbers not used in math | “John” |
| Character | A single letter or symbol | ‘A’ |
| Integer | Whole numbers | 27 |
| Real | Decimal numbers | 3.14 |
| Boolean | TRUE or FALSE | TRUE |
| Date/Time | Dates and timestamps | 01/01/2025 |
🔎 Structured Query Language (SQL)
Used to query and manipulate data in databases.
✅ Basic SQL Keywords
| SQL Keyword | Function |
|---|---|
| SELECT | Retrieves fields from a table |
| FROM | Specifies the table to use |
| WHERE | Filters records by condition |
| ORDER BY | Sorts the result set |
| COUNT() | Returns the number of matching records |
| SUM() | Adds all values in a field |
📌 SQL Examples
1. Retrieve all data from a table
SELECT * FROM Students;
2. Retrieve specific fields
SELECT Name, Age FROM Students;
3. Filter results
SELECT * FROM Students WHERE Age > 16;
4. Sort results
SELECT * FROM Students ORDER BY Age DESC;
5. Count records
SELECT COUNT(*) FROM Students;
6. Sum values in a column
SELECT SUM(Marks) FROM Students;
🔍 Choosing a Primary Key
- Must be unique for each record
- Common options: ID number, registration number
- Not suitable: names (can repeat), addresses
🧪 Validation vs Verification
| Method | Purpose |
|---|---|
| Validation | Checks data is reasonable/correct format |
| Verification | Confirms data has been entered correctly |
