Structured Query Language (SQL)
1. DDL vs. DML
In the 9618 syllabus, you must distinguish between commands that change the schema and those that change the content.
DDL (Data Definition)
Used to create or modify the structure of the database.
CREATE TABLEALTER TABLEDROP TABLE
CREATE TABLE Students (
ID INT PRIMARY KEY,
Name VARCHAR(50)
);
ID INT PRIMARY KEY,
Name VARCHAR(50)
);
DML (Data Manipulation)
Used to manage the data within the existing structure.
SELECT(Queries)INSERT INTOUPDATEDELETE
SELECT Name
FROM Students
WHERE ID = 101;
FROM Students
WHERE ID = 101;
2. Interactive SQL Workbench
Test your DDL and DML commands using the simulator we built. This tool maps your SQL queries to a visual relational model.
Query results will appear here...
π SQL Quick Test Statements
Copy these one-liners into the tool above to see the database in action.
DDL
CREATE TABLE Students (ID INT PRIMARY KEY, Name VARCHAR(50), Grade INT);
DML
INSERT INTO Students (ID, Name, Grade) VALUES (1, 'Alice', 12), (2, 'Bob', 11), (3, 'Charlie', 12);
DML
SELECT Name FROM Students WHERE Grade = 12;
DML
UPDATE Students SET Grade = 12 WHERE Name = 'Bob';
DML
SELECT COUNT(*) FROM Students;
3. Advanced Querying
For Paper 1, focus on these specific clauses:
- INNER JOIN: To combine records from two tables based on a matching attribute.
- ORDER BY: Sort results
ASC(Ascending) orDESC(Descending). - SUM / COUNT / AVG: Aggregate functions for data analysis.
β οΈ Exam Tip: When writing
UPDATE or DELETE, always remember the WHERE clause. Without it, you will update or delete every single row in the tableβa common mistake in exams and real-world production!