A database is an organised collection of related data that can be stored, searched and updated easily. Examples in Kenya include the KNEC candidate registry, M-Pesa transaction records and school admissions lists. A Database Management System (DBMS) such as MySQL, PostgreSQL or Microsoft Access manages the data.
| id | name | class | marks |
|---|---|---|---|
| 1 | Wanjiku | 11A | 78 |
| 2 | Otieno | 11B | 65 |
| 3 | Fatuma | 11A | 91 |
Benefits of using keys: avoids duplication, keeps data consistent (integrity) and speeds searches.
SQL is the standard language for relational databases. Commands end with a semicolon.
SELECT name, marks FROM students; shows two columns.
SELECT * FROM students; shows all columns.
SELECT name FROM students WHERE marks >= 70;
SELECT * FROM students ORDER BY marks DESC;
INSERT INTO students (id, name, class, marks) VALUES (4, 'Kamau', '11B', 55);
UPDATE students SET marks = 60 WHERE id = 4;
DELETE FROM students WHERE id = 4;
Always include WHERE in UPDATE and DELETE. Without it every record changes.
Show the names of Class 11A students sorted by marks, highest first.
SELECT name FROM students WHERE class = '11A' ORDER BY marks DESC;
Result: Fatuma, Wanjiku.
Find the average mark: SELECT AVG(marks) FROM students;
For the table above: (78 + 65 + 91) / 3 = 78.
Other functions: COUNT(), SUM(), MAX(), MIN().
Test yourself with 5 question(s) drawn from this topic - answer online and mark instantly.
Start Databases and SQL Basics quizCreate a free account to bookmark notes, download past papers, track your revision and get AI study help - free for Kenyan students.
Already have one? Log in
Join our list and we'll send fresh study notes and past papers straight to your inbox.