Show that the industry‑standard language for both DDL and DML is Structured Query Language (SQL) and be able to use the core SQL statements required by the Cambridge IGCSE/A‑Level Computer Science (9618) syllabus.
DDL statements describe, modify, or remove the structure of database objects such as tables, indexes, views and constraints. They are normally used by a database designer or DBA when the logical schema is being created or altered.
| Statement | Purpose | Typical example |
|---|---|---|
CREATE | Define a new object (table, view, index, …) | CREATE TABLE Student (id INT PRIMARY KEY, name VARCHAR(50)); |
ALTER | Change the definition of an existing object | ALTER TABLE Student ADD COLUMN birthdate DATE; |
DROP | Permanently remove an object | DROP TABLE Student; |
TRUNCATE | Delete all rows quickly while keeping the table definition (usually non‑transactional) | TRUNCATE TABLE Student; |
RENAME | Give an existing object a new name | RENAME TABLE Student TO Learner; |
CHECK (age >= 0).| Category | Typical types |
|---|---|
| Numeric | INTEGER, SMALLINT, BIGINT, DECIMAL(p,s), NUMERIC, FLOAT |
| Character | CHAR(n), VARCHAR(n), TEXT |
| Date & time | DATE, TIME, TIMESTAMP |
| Boolean | BOOLEAN (TRUE/FALSE) |
DML statements operate on the data stored in the structures created by DDL. They are used daily by developers, analysts and end‑users.
| Statement | Purpose | Typical example |
|---|---|---|
SELECT | Retrieve rows from one or more tables | SELECT name FROM Student WHERE id = 10; |
INSERT | Add new rows | INSERT INTO Student (id, name) VALUES (10, 'Alice'); |
UPDATE | Modify existing rows | UPDATE Student SET name = 'Bob' WHERE id = 10; |
DELETE | Remove rows | DELETE FROM Student WHERE id = 10; |
MERGE | Conditionally INSERT, UPDATE or DELETE in a single statement (supported by many commercial DBMSs) | MERGE INTO Target t USING Source s ON (t.id = s.id) WHEN MATCHED THEN UPDATE SET t.val = s.val WHEN NOT MATCHED THEN INSERT (id, val) VALUES (s.id, s.val); |
COMMIT – permanently saves all changes made in the current transaction.ROLLBACK – discards all changes made in the current transaction.CREATE TABLE, ALTER TABLE, constraints.INSERT statements.SELECT queries and checking that constraints work.ALTER or DROP to refine the schema.COMMIT (or ROLLBACK on error).-- 1️⃣ Create the table (DDL)CREATE TABLE Students (
student_id INTEGER PRIMARY KEY,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
enrolyear INTEGER CHECK (enrolyear >= 2000)
);
-- 2️⃣ Add a column (DDL)
ALTER TABLE Students
ADD COLUMN birthdate DATE;
-- 3️⃣ Insert sample rows (DML)
INSERT INTO Students (studentid, firstname, lastname, enrolyear, birthdate)
VALUES
(1, 'Alice', 'Brown', 2022, '2004-05-12'),
(2, 'Bob', 'Smith', 2021, '2003-11-23'),
(3, 'Charlie', 'Lee', 2023, '2005-02-07');
-- 4️⃣ Retrieve data (DML)
SELECT studentid, firstname, lastname, enrolyear
FROM Students
WHERE enrol_year >= 2022;
-- 5️⃣ Update a row (DML)
UPDATE Students
SET last_name = 'Green'
WHERE student_id = 2;
-- 6️⃣ Delete a row (DML)
DELETE FROM Students
WHERE student_id = 3;
-- 7️⃣ Remove all rows but keep the definition (DDL)
TRUNCATE TABLE Students;
-- 8️⃣ Drop the table when finished (DDL)
DROP TABLE Students;
The following notation shows the essential structure of the core DDL and DML statements. It is deliberately concise – the full SQL grammar is far larger.
ddlstmt ::= CREATE TABLE id '(' coldef {',' col_def}* ')'
| ALTER TABLE id ADD COLUMN col_def
| DROP TABLE id
| TRUNCATE TABLE id
| RENAME TABLE id TO id
dmlstmt ::= SELECT selectlist FROM id [WHERE condition]
| INSERT INTO id '(' id {',' id}* ')' VALUES '(' value {',' value}* ')'
| UPDATE id SET id = value {',' id = value}* [WHERE condition]
| DELETE FROM id [WHERE condition]
| COMMIT | ROLLBACK
COMMIT can leave changes invisible; forgetting ROLLBACK after an error may corrupt the database.TRUNCATE indiscriminately – it cannot be rolled back in many DBMSs and bypasses triggers.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.