SQL statements are grouped into categories to help us understand what each type does. This makes it easier to learn and use SQL for managing data and database structure.
0
0
SQL statement categories (DDL, DML, DQL, DCL)
Introduction
When creating or changing the structure of a database, like adding tables or columns.
When adding, updating, or deleting data inside tables.
When retrieving data from the database to see or use it.
When controlling who can access or change the data.
Syntax
SQL
/* Categories of SQL statements */ -- DDL: Data Definition Language CREATE TABLE table_name (...); ALTER TABLE table_name ...; DROP TABLE table_name; -- DML: Data Manipulation Language INSERT INTO table_name VALUES (...); UPDATE table_name SET column = value WHERE ...; DELETE FROM table_name WHERE ...; -- DQL: Data Query Language SELECT column1, column2 FROM table_name WHERE ...; -- DCL: Data Control Language GRANT privilege ON object TO user; REVOKE privilege ON object FROM user;
Each category groups commands by their purpose.
Some commands may overlap but are mainly used in one category.
Examples
This is a DDL command to create a new table called Students.
SQL
CREATE TABLE Students (ID INT, Name VARCHAR(50));
This is a DML command to add a new row to the Students table.
SQL
INSERT INTO Students VALUES (1, 'Alice');
This is a DQL command to get the name of the student with ID 1.
SQL
SELECT Name FROM Students WHERE ID = 1;
This is a DCL command to give user1 permission to read data from Students.
SQL
GRANT SELECT ON Students TO user1;
Sample Program
This example shows creating a table, adding data, retrieving it, and giving access permission.
SQL
CREATE TABLE Employees (ID INT, Name VARCHAR(50)); INSERT INTO Employees VALUES (1, 'John'); INSERT INTO Employees VALUES (2, 'Jane'); SELECT * FROM Employees; GRANT SELECT ON Employees TO user2;
OutputSuccess
Important Notes
DDL commands change the structure of the database.
DML commands change the data inside tables.
DQL commands read data without changing it.
DCL commands manage user permissions.
Summary
SQL statements are grouped into DDL, DML, DQL, and DCL categories.
Each category has a clear role: structure, data, query, or control.
Knowing these helps you use SQL effectively and understand what commands do.