If you’re learning SQL, you’ve probably met SELECT first. But before you can query anything, the database needs a structure: tables, columns, and rules. That part of SQL is called DDL - Data Definition Language.
A simple way to think about it: DDL is like designing and building a house. You decide how many rooms, where the doors go, and what each room is for.
What Is SQL DDL?
Data Definition Language (DDL) is the part of SQL used to define and change the structure of the database - the tables, columns, and constraints.
- CREATE - build a new table or database object.
- ALTER - change something that already exists.
- DROP - remove a table or object completely.
You can think of them like this: CREATE = build the house, ALTER = renovate, DROP = demolish. As an analyst, you might not run DDL every day, but understanding it helps you read and design schemas with confidence.
CREATE TABLE - How a Table Is Born
Imagine a form you fill in for every customer: customer id, name, email, signup date. In the database, that form becomes a row, and each question becomes a column.
Generic CREATE TABLE pattern:
CREATE TABLE table_name (
column1 data_type constraints,
column2 data_type constraints,
...
);Example customers table:
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
email VARCHAR(150),
signup_date DATE
);Notice how constraints like PRIMARY KEY and NOT NULL already prevent some dirty data from entering the table. That’s the connection between DDL and data cleaning.
ALTER TABLE - Changing Your Design Safely
Real life changes. Maybe you need a phone number, a VIP flag, or a clearer column name. You don’t throw away the table; you ALTER it.
Examples:
-- Add a new column ALTER TABLE customers ADD COLUMN phone VARCHAR(30); -- Rename a column (syntax can vary) ALTER TABLE customers RENAME COLUMN full_name TO customer_name;
DROP TABLE - Use with Respect
DROP TABLE removes both structure and data. It’s more like deleting the whole file, not just hiding a sheet.
DROP TABLE customers;
In production systems, DROP is used carefully, usually in test environments or after backups.
How DDL Connects to Data Cleaning
Bad table design leads to dirty data later: numbers stored as text, dates stored as free text, nullable columns that should never be null, IDs that are not unique.
Good DDL reduces those problems using proper data types, NOT NULL, UNIQUE, PRIMARY KEY, and sensible lengths for text columns. A strong analyst doesn’t just fix data downstream - they can also suggest better table designs upstream.
DDL vs DML vs DCL - The Big Picture
- DDL - structure: CREATE, ALTER, DROP.
- DML - data: SELECT, INSERT, UPDATE, DELETE.
- DCL - permissions: GRANT, REVOKE.
You don’t have to memorise the labels for an exam, but knowing the groups makes SQL feel less random and more like a well-organised toolbox.
How to Practise DDL as a Beginner
- Pick a real-life scenario (e.g., customers, orders, playlists).
- Design a CREATE TABLE statement for it.
- Add constraints like PRIMARY KEY, NOT NULL, and UNIQUE where they make sense.
- Use ALTER TABLE to improve names or add new columns as you learn.
As you practise on Bampaa or in your own environment, remind yourself: every clean dataset sits on top of thoughtful DDL choices.
Try it yourself
CREATE TABLE is Level 43, in Chapter 7: Creating and changing tables.
The first 5 levels are free · no sign-up needed