Published by Patrick Mutisya · 14 days ago
Understand that the Database Management System (DBMS) executes all queries and maintains data exclusively through its Data Manipulation Language (DML). Recognise the complementary role of Data Definition Language (DDL) in defining the structure on which DML operates.
DDL consists of SQL statements that define, modify, and remove database objects such as tables, indexes, views and schemas. These statements are interpreted by the DBMS to change the metadata (the data dictionary).
DML comprises the statements that actually manipulate the data stored in the structures created by DDL. The DBMS processes these statements, applying transaction control, integrity checking and concurrency management.
| Aspect | DDL | DML |
|---|---|---|
| Purpose | Define and modify database schema. | Manipulate the actual data within the schema. |
| Typical Commands | CREATE, ALTER, DROP, TRUNCATE, RENAME. | SELECT, INSERT, UPDATE, DELETE, MERGE. |
| Effect on Data | Indirect – changes structure that holds data. | Direct – adds, changes, or removes data rows. |
| Transaction Control | Usually auto‑committed; cannot be rolled back in many DBMS. | Subject to COMMIT and ROLLBACK; fully transactional. |
| Execution by DBMS | Updates system catalog; may lock schema objects. | Uses query optimizer, execution engine, and concurrency manager. |
The DBMS follows a well‑defined pipeline for every DML statement:
Below is a simple scenario for a university database.
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
Name \cdot ARCHAR(100) NOT NULL,
DOB DATE,
Programme \cdot ARCHAR(50)
);
INSERT INTO Student (StudentID, Name, DOB, Programme)
VALUES (101, 'Alice Brown', '2002-04-15', 'Computer Science');
SELECT Name, Programme
FROM Student
WHERE Programme = 'Computer Science';
UPDATE Student
SET Programme = 'Software Engineering'
WHERE StudentID = 101;
DELETE FROM Student
WHERE StudentID = 101;
All DML operations are part of a transaction. The following SQL demonstrates explicit transaction control:
BEGIN TRANSACTION;
INSERT INTO Student (StudentID, Name, DOB, Programme)
VALUES (102, 'Bob Carter', '2001-09-30', 'Mathematics');
UPDATE Student
SET Programme = 'Data Science'
WHERE StudentID = 102;
-- If any statement fails, undo all changes
IF @@ERROR <> 0
ROLLBACK TRANSACTION;
ELSE
COMMIT TRANSACTION;
From a theoretical point of view, DML corresponds to relational algebra operations. For example, the SELECT query above can be expressed as:
\$\sigma_{\text{Programme} = \text{'Computer Science'}}(\text{Student})\$
where \$\sigma\$ denotes the selection operator.