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.
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 LanguageCREATETABLE table_name (...);
ALTERTABLE table_name ...;
DROPTABLE table_name;
-- DML: Data Manipulation LanguageINSERTINTO table_name VALUES (...);
UPDATE table_name SET column = value WHERE ...;
DELETEFROM table_name WHERE ...;
-- DQL: Data Query LanguageSELECT 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
CREATETABLE Students (ID INT, Name VARCHAR(50));
This is a DML command to add a new row to the Students table.
SQL
INSERTINTO 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 SELECTON Students TO user1;
Sample Program
This example shows creating a table, adding data, retrieving it, and giving access permission.
SQL
CREATETABLE Employees (ID INT, Name VARCHAR(50));
INSERTINTO Employees VALUES (1, 'John');
INSERTINTO Employees VALUES (2, 'Jane');
SELECT * FROM Employees;
GRANT SELECTON 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.
Practice
(1/5)
1. Which category of SQL statements is used to create or modify the structure of database objects like tables and indexes?
easy
A. Data Manipulation Language (DML)
B. Data Query Language (DQL)
C. Data Definition Language (DDL)
D. Data Control Language (DCL)
Solution
Step 1: Understand the role of DDL
DDL commands define or change database structures, such as creating tables or indexes.
Step 2: Differentiate from other categories
DML changes data, DQL queries data, and DCL controls access, so they don't modify structure.
Final Answer:
Data Definition Language (DDL) -> Option C
Quick Check:
Structure changes = DDL [OK]
Hint: Structure changes mean DDL commands [OK]
Common Mistakes:
Confusing DDL with DML because both change something
Thinking SELECT is DDL instead of DQL
Mixing up DCL with DDL
2. Which of the following is the correct syntax to grant SELECT permission on a table named employees to a user john?
easy
A. GRANT SELECT TO john ON employees;
B. GRANT john ON employees SELECT;
C. SELECT GRANT ON employees TO john;
D. GRANT SELECT ON employees TO john;
Solution
Step 1: Recall correct GRANT syntax
The correct syntax is: GRANT permission ON object TO user;
Step 2: Match syntax with options
GRANT SELECT ON employees TO john; matches the correct order and keywords exactly.
Final Answer:
GRANT SELECT ON employees TO john; -> Option D
Quick Check:
GRANT + permission + ON + object + TO + user [OK]
Hint: GRANT syntax: GRANT permission ON object TO user [OK]
Common Mistakes:
Swapping TO and ON keywords
Placing user before permission
Using SELECT before GRANT
3. What will be the output of the following SQL statement?
SELECT * FROM employees WHERE salary > 50000;
medium
A. All rows from employees with salary greater than 50000
B. All rows from employees with salary less than 50000
C. Syntax error due to missing semicolon
D. No rows because salary column does not exist
Solution
Step 1: Understand the SELECT query
The query selects all columns (*) from employees where salary is greater than 50000.
Step 2: Analyze the WHERE condition
Only rows with salary > 50000 are returned; others are excluded.
Final Answer:
All rows from employees with salary greater than 50000 -> Option A
Quick Check:
WHERE salary > 50000 filters rows correctly [OK]
Hint: WHERE filters rows; > means greater than [OK]
Common Mistakes:
Confusing > with <
Thinking semicolon is mandatory for output
Assuming salary column missing without info
4. Identify the error in the following SQL statement:
INSERT INTO employees (id, name salary) VALUES (1, 'Alice', 60000);
medium
A. Missing comma between columns 'name' and 'salary'
B. VALUES keyword is misspelled
C. Table name should be in quotes
D. Cannot insert numeric value into salary column
Solution
Step 1: Check column list syntax
Columns must be separated by commas; here 'name' and 'salary' lack a comma.
Step 2: Verify other parts
VALUES is correct, table name does not need quotes, numeric salary is valid.
Final Answer:
Missing comma between columns 'name' and 'salary' -> Option A
Quick Check:
Column list commas are required [OK]
Hint: Check commas between column names carefully [OK]
Common Mistakes:
Ignoring missing commas in column list
Thinking table names need quotes
Assuming VALUES keyword typo
5. You want to remove a table named orders and all its data permanently from the database. Which SQL statement category should you use, and which command is correct?
hard
A. DML - DELETE FROM orders;
B. DDL - DROP TABLE orders;
C. DCL - REVOKE ALL ON orders;
D. DQL - SELECT * FROM orders;
Solution
Step 1: Understand the goal
Removing a table and its data permanently means deleting the structure, not just data.
Step 2: Identify correct category and command
DDL commands modify structure; DROP TABLE removes the table entirely.
Final Answer:
DDL - DROP TABLE orders; -> Option B
Quick Check:
Drop table = remove structure and data [OK]
Hint: DROP removes table; DELETE removes data only [OK]
Common Mistakes:
Using DELETE which only removes data, not table
Confusing REVOKE with deleting tables
Thinking SELECT can remove anything
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.