Grade 12 Computer Studies: Database Design and SQL Notes (Kenya) | YNetStudyHub

Database Design and SQL

Grade 12 · Computer Studies 6 min read

Database Design and SQL

What is a database?

A database is an organised collection of related data stored so it can be accessed, managed and updated easily. A DBMS (database management system) such as MySQL or MS Access controls it. Examples in Kenya: KCSE results, M-Pesa transaction logs, school fee records, county land registries.

Terms

  • Table: data arranged in rows and columns.
  • Record (row): one entry, e.g. one student.
  • Field (column): one attribute, e.g. name.
  • Primary key: uniquely identifies each record (admission number).
  • Foreign key: a field linking to a primary key in another table.

Relationships

  • One-to-one: one learner has one NEMIS UPI number.
  • One-to-many: one class has many students.
  • Many-to-many: students take many subjects and each subject has many students (solved with a link table).

Designing a database

  1. Identify the purpose.
  2. List entities (students, subjects, teachers).
  3. Define fields and data types (text, integer, date).
  4. Choose primary keys.
  5. Set relationships.
  6. Apply normalisation.
  7. Test with sample data.

Normalisation

  • 1NF: each field holds one value; no repeating groups.
  • 2NF: 1NF and every non-key field depends on the whole primary key.
  • 3NF: 2NF and no non-key field depends on another non-key field.

Benefits: less redundancy, easier updates, better integrity.

SQL basics

SQL (Structured Query Language) has:

  • DDL: CREATE, ALTER, DROP
  • DML: INSERT, UPDATE, DELETE, SELECT

Create a table:

CREATE TABLE students (
  admno INT PRIMARY KEY,
  name VARCHAR(50),
  class VARCHAR(5),
  marks INT
);

Insert:

INSERT INTO students VALUES (101, 'Achieng', '12A', 78);

Select with condition:

SELECT name, marks FROM students WHERE marks >= 50 ORDER BY marks DESC;

Update and delete:

UPDATE students SET marks = 80 WHERE admno = 101;
DELETE FROM students WHERE admno = 105;

Aggregate functions

COUNT, SUM, AVG, MIN, MAX with GROUP BY:

SELECT class, COUNT(*) FROM students GROUP BY class;

Joins

If marks are in a separate table:

SELECT students.name, results.score
FROM students JOIN results ON students.admno = results.admno;

Data integrity and security

Use validation rules, backups, user permissions and passwords. The Data Protection Act, 2019 requires careful handling of personal data, including learners' details.

Worked example

Count students scoring 60 or more in each class: SELECT class, COUNT(*) FROM students WHERE marks >= 60 GROUP BY class;

Try it

  • Design two tables for a school library and link them with a foreign key.
  • Write a query listing all students in class 12B.
  • Normalise a table that stores student name, subject1, subject2 and subject3 in one row.

Revise Database Design and SQL

Test yourself with 5 question(s) drawn from this topic - answer online and mark instantly.

Start Database Design and SQL quiz
Want to save these Database Design and SQL notes?

Create a free account to bookmark notes, download past papers, track your revision and get AI study help - free for Kenyan students.

Save & bookmark notes Download past papers Track revision progress AI study help
Create free account

Already have one? Log in

Frequently Asked Questions

Database Design and SQL is a Grade 12 Computer Studies topic. This page gathers clear, exam-focused notes and revision material for it, all free to read online.

Yes - every note on this page is free to read online on YNetStudyHub, with no sign-up required.

Read the notes below, write a short summary of each in your own words, then practise related questions from the Computer Studies past papers to check your understanding.
Get free notes & past papers by email

Join our list and we'll send fresh study notes and past papers straight to your inbox.