| Model | Structure | Typical Use‑case | Advantages | Disadvantages |
|---|---|---|---|---|
| Relational | Tables (rows & columns) | Business applications, MIS, web‑based systems | SQL, strong data integrity, widely supported | Less efficient for deep hierarchies |
| Hierarchical | Tree‑like parent‑child structure | File systems, XML storage | Fast parent‑child navigation | Rigid, difficult many‑to‑many queries |
| Network | Graph of records linked by sets | Complex engineering data, CAD | Efficient many‑to‑many navigation | Complex design, limited portability |
| Object‑Oriented | Objects, classes, inheritance | Multimedia, software engineering | Stores data + behaviour, aligns with OO programming | Immature query language, steeper learning curve |
| Aspect | Flat‑File (e.g., CSV) | Relational DB |
|---|---|---|
| Structure | Single table, no relationships | Multiple tables linked by keys |
| Redundancy | High – same data repeated | Low – normalisation removes duplication |
| Query Capability | Limited (text search, filters) | Powerful SQL (joins, aggregates, sub‑queries) |
| Data Integrity | None – no constraints | Enforced by primary/foreign keys, CHECK, UNIQUE |
| Scalability | Poor for large data sets | Designed for large, concurrent users |
Scenario: A school wants to store students, courses and enrolments. With a flat file each enrolment row would repeat student and course details, leading to inconsistencies. A relational design stores each entity once and links them via keys, guaranteeing consistency.
| SQL Type | Typical Use | Size / Precision |
|---|---|---|
| INT | Whole numbers (e.g., StudentID) | ‑2 147 483 648 to 2 147 483 647 |
| SMALLINT | Small whole numbers | ‑32 768 to 32 767 |
| DECIMAL(p,s) | Currency, precise values | p = total digits, s = digits after decimal |
| FLOAT | Approximate numeric values | Variable |
| CHAR(n) | Fixed‑length text (e.g., gender code) | n characters, padded with spaces |
| VARCHAR(n) | Variable‑length text (e.g., names) | up to n characters |
| DATE | Calendar dates | YYYY‑MM‑DD |
| BOOLEAN | True/False values | TRUE / FALSE |
| TEXT | Long free‑form strings (e.g., comments) | Unlimited length |
(StudentID, CourseCode) in an enrolment table).CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(30) NOT NULL,
LastName VARCHAR(30) NOT NULL,
Email VARCHAR(50) UNIQUE
);
CREATE TABLE Enrolments (
StudentID INT,
CourseCode CHAR(6),
EnrolDate DATE,
PRIMARY KEY (StudentID, CourseCode),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
);
If we try to insert an enrolment for a non‑existent student, the DBMS rejects it:
INSERT INTO Enrolments (StudentID, CourseCode, EnrolDate)
VALUES (999, 'CS101', '2023-09-01'); -- ERROR: foreign key violation
Conceptual: Entities = Student, Course, Enrolment; Relationships = Enrols (Student ↔ Enrolment ↔ Course).
Logical (textual description):
StudentID (PK), FirstName, LastName, EmailCourseCode (PK), CourseName, Lecturer, CreditsStudentID (FK), CourseCode (FK), EnrolDate – cardinality 1:M from Student to Enrolment and 1:M from Course to Enrolment.Physical (SQL DDL):
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(30) NOT NULL,
LastName VARCHAR(30) NOT NULL,
Email VARCHAR(50) UNIQUE,
CHECK (Email LIKE '%@%')
);
CREATE TABLE Courses (
CourseCode CHAR(6) PRIMARY KEY,
CourseName VARCHAR(50) NOT NULL,
Lecturer VARCHAR(30),
Credits SMALLINT CHECK (Credits BETWEEN 1 AND 6)
);
CREATE TABLE Enrolments (
StudentID INT,
CourseCode CHAR(6),
EnrolDate DATE,
PRIMARY KEY (StudentID, CourseCode),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseCode) REFERENCES Courses(CourseCode)
);
Given the above conceptual diagram, list the three ERD stages and write the CREATE TABLE statements that include appropriate keys and constraints.
-- Un‑normalised table (student enrolments)
StudentCourses
--------------------------------------------------------------
StudentID | StudentName | CourseCode | CourseName | Lecturer | Credits
--------------------------------------------------------------
101 | Alice Brown | CS101 | Computing | Dr. Lee | 3
101 | Alice Brown | MA101 | Maths | Dr. Kim | 4
102 | Bob Smith | CS101 | Computing | Dr. Lee | 3
StudentID:
Students(StudentID PK, StudentName)Courses(CourseCode PK, CourseName, Lecturer, Credits)Enrollments(StudentID FK, CourseCode FK)Courses, Lecturer depends on CourseCode only, so 3NF satisfied.The resulting schema eliminates duplicate student and course data and satisfies 3NF.
A data dictionary records the definition of every field used in a database. It is a key reference for developers and users.
| Field Name | Data Type | Size | Description | Constraints |
|---|---|---|---|---|
| StudentID | INT | 4 bytes | Unique identifier for each student | PK, NOT NULL |
| FirstName | VARCHAR | 30 | Student’s given name | NOT NULL |
| LastName | VARCHAR | 30 | Student’s family name | NOT NULL |
| VARCHAR | 50 | Student’s email address | UNIQUE, CHECK (Email LIKE '%@%') | |
| DOB | DATE | — | Date of birth | CHECK (DOB < CURRENT_DATE) |
| CourseCode | CHAR | 6 | Code of the course | PK, NOT NULL |
| Credits | SMALLINT | 2 bytes | Credit value of the course | CHECK (Credits BETWEEN 1 AND 6) |
-- Create tables with full set of constraints
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(30) NOT NULL,
LastName VARCHAR(30) NOT NULL,
DOB DATE CHECK (DOB < CURRENT_DATE),
Email VARCHAR(50) UNIQUE CHECK (Email LIKE '%@%')
);
CREATE TABLE Courses (
CourseCode CHAR(6) PRIMARY KEY,
CourseName VARCHAR(50) NOT NULL,
Lecturer VARCHAR(30),
Credits SMALLINT CHECK (Credits BETWEEN 1 AND 6)
);
CREATE TABLE Enrolments (
StudentID INT,
CourseCode CHAR(6),
EnrolDate DATE DEFAULT CURRENT_DATE,
PRIMARY KEY (StudentID, CourseCode),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseCode) REFERENCES Courses(CourseCode)
);
| Operation | SQL Statement | Purpose |
|---|---|---|
| Insert | INSERT INTO Students (StudentID, FirstName, LastName, DOB, Email)
VALUES (101, 'Alice', 'Brown', '2002-04-15', 'alice.brown@example.com'); |
Add a new record. |
| Update | UPDATE Students
SET Email = 'alice.b@example.org'
WHERE StudentID = 101; |
Correct or change existing data. |
| Delete | DELETE FROM Enrolments
WHERE StudentID = 101 AND CourseCode = 'CS101'; |
Remove records that are no longer required. |
| Select (simple) | SELECT FirstName, LastName, Email
FROM Students
WHERE DOB > '2000-01-01'
ORDER BY LastName; |
Retrieve specific columns with a filter and sorting. |
SELECT * FROM Courses WHERE Credits = 3;
SELECT * FROM Courses WHERE Credits = ?;
SELECT FirstName FROM Students WHERE StudentID = 101;
SELECT s.FirstName, c.CourseName
FROM Students s
JOIN Enrolments e ON s.StudentID = e.StudentID
JOIN Courses c ON e.CourseCode = c.CourseCode
WHERE c.Credits > 3
ORDER BY s.LastName;
SELECT StudentID, FirstName
FROM Students
WHERE StudentID IN (
SELECT StudentID
FROM Enrolments
WHERE CourseCode = 'CS101'
);
SELECT CourseCode, COUNT(*) AS EnrolCount
FROM Enrolments
GROUP BY CourseCode
HAVING COUNT(*) > 10;
SELECT CourseCode,
SUM(CASE WHEN Semester='Spring' THEN 1 ELSE 0 END) AS Spring,
SUM(CASE WHEN Semester='Fall' THEN 1 ELSE 0 END) AS Fall
FROM Enrolments
GROUP BY CourseCode;
| Operator | Purpose | Example |
|---|---|---|
| LIKE | Pattern matching with wildcards | WHERE Email LIKE '%@school.edu' |
| % | Wildcard – any sequence of characters | LIKE 'A%' |
| _ | Wildcard – single character | LIKE 'A_' |
| AND, OR, NOT | Boolean logic | WHERE Credits > 3 AND Lecturer = 'Dr. Lee' |
| >, <, =, <> | Comparison | WHERE Credits >= 4 |
SELECT CourseCode, CourseName, Credits
FROM Courses
ORDER BY Credits DESC, CourseName ASC;
CHECK constraints or application‑side code).CHECK (Email LIKE '%@%')
StudentID triggers a referential‑integrity error.A transaction groups several DML statements so that they either all succeed (COMMIT) or all fail (ROLLBACK).
BEGIN TRANSACTION;
INSERT INTO Orders (OrderID, StudentID, OrderDate)
VALUES (5001, 101, CURRENT_DATE);
UPDATE Products
SET Stock = Stock - 1
WHERE ProductID = 200;
-- Validation step: stock must stay non‑negative
IF (SELECT Stock FROM Products WHERE ProductID = 200) < 0
ROLLBACK; -- abort whole transaction
ELSE
COMMIT; -- make all changes permanent
| Category | Typical Extension | Characteristics |
|---|---|---|
| Generic (plain text) | .txt, .csv, .xml | Human‑readable, easy to import/export, platform independent. |
| Proprietary (application‑specific) | .mdb, .accdb, .dbf, .sqlite | Optimised for a particular DBMS; may need that DBMS to read/write. |
CREATE TABLE statements.BEGIN, COMMIT and ROLLBACK.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.