When a specification tells you what information must be stored, the first step is to convert it into a table design. A table consists of:
NOT NULL, UNIQUE).Example specification: “A school needs a register of students. For each student the register must store a unique student ID, the full name, age, gender and e‑mail address.”
The IGCSE syllabus recognises five basic data‑type categories. The table below shows the typical SQL type used in MySQL/PostgreSQL and an example field from the student register.
| Data‑type category | SQL type (MySQL / PostgreSQL) | Example field |
|---|---|---|
| INTEGER | INT |
age |
| REAL (floating‑point) | REAL or FLOAT |
average_mark |
| CHAR (fixed length) | CHAR(n) |
student_id (8 characters) |
| STRING (variable length) | VARCHAR(n) or TEXT |
name, email |
| BOOLEAN | BOOLEAN |
is_full_time (TRUE/FALSE) |
NULL.student_id CHAR(8) meets all criteria, so it is declared as the primary key.Students must be able to write and interpret basic SELECT statements using the following clauses:
SELECT – list the required fields.FROM – specify the table.WHERE – filter rows; combine conditions with AND, OR.ORDER BY – sort the result set.SUM(), COUNT().Example queries based on the Students table:
-- 1. List names and ages of students older than 10, sorted alphabetically
SELECT name, age
FROM Students
WHERE age > 10
ORDER BY name ASC;
-- 2. Count how many students are registered
SELECT COUNT(*) AS total_students
FROM Students;
-- 3. Total salary of all IT‑department staff
SELECT SUM(salary) AS total_it_salary
FROM Employees
WHERE department = 'IT';
Data validation checks that data entered into a database satisfies all required rules before it is stored. Validation protects data integrity and reduces the amount of later cleaning.
| Validation type | SQL feature | Example syntax |
|---|---|---|
| Data‑type | Column definition | age INT |
| Length | VARCHAR(n) or CHAR(n) |
username VARCHAR(15) |
| Range | CHECK constraint |
age INT CHECK (age BETWEEN 5 AND 20) |
| Format | CHECK with LIKE or REGEXP |
email VARCHAR(255) CHECK (email LIKE '%_@_%._%') |
| Mandatory | NOT NULL |
name VARCHAR(30) NOT NULL |
| Uniqueness | UNIQUE constraint |
student_id CHAR(8) UNIQUE |
When a rule cannot be expressed with a simple CHECK constraint, a trigger can examine the data before it is inserted or updated.
CREATE TRIGGER trg_check_salary
BEFORE INSERT ON Employees
FOR EACH ROW
BEGIN
IF NEW.salary < 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Salary cannot be negative';
END IF;
END;
required, pattern, type="number").HTML5 form fields (client‑side):
<input type="text" name="student_id" pattern="[A-Za-z0-9]{8}" required>
<input type="text" name="name" maxlength="30" required>
<input type="number" name="age" min="5" max="20" required>
<input type="email" name="email" required>
SQL table definition (server‑side constraints):
CREATE TABLE Students (
student_id CHAR(8) PRIMARY KEY,
name VARCHAR(30) NOT NULL,
age INT CHECK (age BETWEEN 5 AND 20),
email VARCHAR(255) NOT NULL,
UNIQUE (student_id)
);
CHECK constraints treat NULL as “unknown”, so a NULL value can bypass a range check.SELECT queries using SELECT, FROM, WHERE, ORDER BY, AND, OR, SUM, COUNT.NOT NULL, UNIQUE, CHECK).CHECK.Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.