DEV Community

Davy Baraka
Davy Baraka

Posted on

Understanding DDL and DML SQL concepts

1. INTRODUCTION

This article will cover an introduction to SQL concepts
SQL (Structured Query Language) is a standard language that is used to communicate with relational databases. It is used to store, retrieve, manipulate, and manage data that is organised in tables.

Core concepts in SQL consist of the following:

  1. DDL (Data Definition Language) Used to define database structure Includes: create, alter, drop, truncate, rename
  2. DML (Data Manipulation Language) Used to modify data Includes: insert, update, delete
  3. DQL (Data Query Language) Used to retrieve data Includes: select, where, order by, group by, having, join
  4. DCL (Data Control Language) Used to control access Includes: grant, revoke
  5. TCL (Transaction Query Language) Used to manage transactions Includes: commit, rollback, savepoint

## 2. What DDL and DML are, and the difference between them

DDL

DDL commands deal with the structure of a database. They define, modify, or remove the objects that hold data — like tables, schemas, and columns. Think of DDL as the blueprint stage: you are not yet putting data in; you are deciding how that data will be organised.
DDL commands include:

  • CREATE is used to create new tables or databases.
  • ALTER is used to modify existing structures.
  • DROP is used to delete tables or databases.

DML

DML commands, on the other hand, deal with the actual data inside those structures. Once your table exists, you use DML to add records, update them, or remove them.
DML commands include:

  • INSERT adds new records
  • UPDATE modifies existing records
  • DELETE removes records
  • SELECT retrieves data

Key difference:
DDL deals with the structure of the database, while DML deals with the data inside the database.

**3. How you used CREATE, INSERT, UPDATE, and DELETE in your assignment

**
CREATE:I used it to create tables such as students.

INSERT:I used it to insert records in the tables.

UPDATE: I used to modify existing records, such as correcting a student's score

DELETE: I used it to delete unwanted or incorrect records, such as deleting a student entry.

3. How filtering with WHERE works (mention some operators like =, >, BETWEEN, IN, LIKE)

The WHERE clause is how SQL narrows down which rows a query applies to. Whether you are reading data with SELECT, changing it with UPDATE, or removing it with DELETE, WHERE lets you be precise.

SQL provides several operators you can use inside a WHERE condition:

  • = (equals) — Matches an exact value. Example: WHERE score = 80 returns only students with a grade of A.
  • > and < (greater/less than) — Compare numeric or date values. Example: WHERE score > 80 returns students who scored above 80.
  • BETWEEN — Selects values within a range (inclusive on both ends). Example: WHERE score BETWEEN 50 AND 80 returns students who scored between 50 and 80.
  • IN — Checks whether a value appears in a given list. Example: WHERE subject IN ('Math', 'Science') returns students doing either maths or science.
  • LIKE — Enables pattern matching in text. The % symbol acts as a wildcard. Example: WHERE full_name LIKE 'A%' returns all students whose names start with the letter A.

These operators can also be combined using AND and OR to build more complex filters, making WHERE one of the most powerful tools in SQL.

4. How CASE WHEN helps in transforming data

CASE WHEN is SQL's way of applying conditional logic — similar to an if/else statement in programming. It lets you create a new column in your query result based on conditions, without changing the underlying data in the table.

The basic structure looks like this:

Top comments (0)