DDL defines or changes the structure of a database, whereas DML retrieves or changes the data stored within that structure. In short, DDL acts on database objects such as tables, while DML acts on records inside those tables.
In A3.3 Database programming, Data Definition Language (DDL) is the part of SQL used to create, modify, or remove a database schema and its objects. For example:
CREATE TABLE Student (
studentID INTEGER PRIMARY KEY,
name VARCHAR(50)
);
This statement defines a table, its fields, data types, and primary key. Other common DDL commands are ALTER, which changes an existing structure, and DROP, which removes an object.
Data Manipulation Language (DML) is used to access and manipulate the records stored in those structures. For example:
INSERT INTO Student (studentID, name)
VALUES (101, 'Aisha');
This adds a record without changing the table's design. DML also includes UPDATE, DELETE, and, in the broad SQL classification normally used at this level, SELECT.
| Feature | DDL | DML |
|---|---|---|
| Main purpose | Defines database structure | Retrieves or manipulates stored data |
| Acts on | Tables, fields, constraints, schemas | Rows and field values |
| Typical commands | CREATE, ALTER, DROP | SELECT, INSERT, UPDATE, DELETE |
| Example effect | Adds a new column | Changes a student's name |
A common misconception is that DELETE and DROP are interchangeable. DELETE FROM Student; removes records but keeps the table, whereas DROP TABLE Student; removes the table definition itself.
For an IB exam response, define both terms, state what each acts upon, and support the distinction with correctly formed SQL examples. If asked to distinguish them, do not merely list commands: explain the difference between changing the schema and changing the data.