A3.3.1 Outline the differences between data language types within SQL.
• Data language types must include data definition language (DDL) and data manipulation language (DML)
• SQL statements to define data structures or to manipulate data
📚 You can find additional information related to these learning standards in the course companion pages 191 to 195
The Big Idea
Structured Query Language (SQL) is the standard language for managing relational databases. Within SQL, there are subsets of commands designed for different tasks. Two of the most fundamental subsets are:
- Data Definition Language (DDL): used to define and modify the structure of database objects (tables, schemas, indexes, etc.).
- Data Manipulation Language (DML): used to manipulate the data inside those objects (inserting, updating, deleting, querying rows).
Each serves a distinct purpose in the lifecycle of a relational database system.
1. Data Definition Language (DDL)
Purpose
Defines, alters, or removes schema-level structures.
Common DDL Statements
| Command | Description |
|---|---|
CREATE | Creates new database objects like tables, views, indexes |
ALTER | Modifies an existing object (add/remove columns, constraints) |
DROP | Permanently deletes objects from the schema |
TRUNCATE | Deletes all data from a table but keeps the structure |
Example – Create a table
CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(100),
birth_date DATE
);
Example – Add a column
ALTER TABLE students ADD COLUMN email VARCHAR(255);
2. Data Manipulation Language (DML)
Purpose
Performs actions on the data itself, inside the objects defined using DDL.
Common DML Statements
| Command | Description |
|---|---|
SELECT | Retrieves data from tables |
INSERT | Adds new rows |
UPDATE | Modifies existing rows |
DELETE | Removes rows |
Example – Insert a record
INSERT INTO students (student_id, name, birth_date)
VALUES (101, 'Alice Smith', '2006-11-15');
Example – Retrieve records
SELECT name, birth_date FROM students WHERE student_id = 101;
Summary Table
| Category | DDL (Data Definition Language) | DML (Data Manipulation Language) |
|---|---|---|
| Focus | Structure/schema | Data/rows |
| Examples | CREATE, ALTER, DROP, TRUNCATE | SELECT, INSERT, UPDATE, DELETE |
| Use Case | Create or modify a table | Add, change, remove, or query data in a table |
| Persistence | Usually auto-committed and affects structure permanently | May require explicit transaction control (e.g., COMMIT) |
Conclusion
In SQL, DDL defines the "shape" of the database, while DML populates and modifies its contents. Understanding the difference is foundational to effective database development: DDL builds the house, DML moves the furniture. Both are essential in the design, implementation, and operation of relational database systems.