SQL commands fall into five groups by what they act on. DDL (CREATE, ALTER, DROP, TRUNCATE) defines tables. DML (INSERT, UPDATE, DELETE) changes the rows inside them. DQL (SELECT) reads data. DCL (GRANT, REVOKE) controls who may do what. TCL (COMMIT, ROLLBACK, SAVEPOINT) decides whether a set of changes is kept or undone.
This page lists every command in each group with its syntax and an example, then walks through them on one small table so you can see what each does to the data. It ends with the clauses inside SELECT, because that is where a data analyst spends most of the working day.
The five groups at a glance
| Group | Full name | Acts on | Commands |
|---|---|---|---|
| DDL | Data Definition Language | Structure: tables, columns, indexes | CREATE, ALTER, DROP, TRUNCATE, RENAME |
| DML | Data Manipulation Language | The rows inside tables | INSERT, UPDATE, DELETE, MERGE |
| DQL | Data Query Language | Reading rows | SELECT |
| DCL | Data Control Language | Permissions | GRANT, REVOKE |
| TCL | Transaction Control Language | Groups of changes | COMMIT, ROLLBACK, SAVEPOINT |
Some textbooks put SELECT under DML and skip DQL entirely, which is why one website says SQL has four command types and another says five. Both are describing the same commands. If an interviewer asks, give the five-group answer and mention that SELECT is sometimes counted as DML; that shows you know the debate exists.
The complete SQL commands list
Every command in the five groups, with its syntax and a one-line example. The examples use a menu table for a Hyderabad cloud kitchen, which the walkthrough below builds step by step.
| Command | Group | What it does | Example |
|---|---|---|---|
| CREATE | DDL | Makes a table, database, view or index | CREATE TABLE menu (dish_id INT PRIMARY KEY, dish_name VARCHAR(60), category VARCHAR(20), price INT) |
| ALTER | DDL | Changes a table’s structure | ALTER TABLE menu ADD is_veg BOOLEAN |
| DROP | DDL | Deletes a table and its structure | DROP TABLE menu |
| TRUNCATE | DDL | Removes all rows, keeps the empty table | TRUNCATE TABLE menu |
| RENAME | DDL | Renames a table (MySQL) | RENAME TABLE menu TO menu_items |
| INSERT | DML | Adds rows | INSERT INTO menu VALUES (1, ‘Chicken Dum Biryani’, ‘Biryani’, 329) |
| UPDATE | DML | Changes values in existing rows | UPDATE menu SET price = price + 20 WHERE category = ‘Biryani’ |
| DELETE | DML | Removes chosen rows | DELETE FROM menu WHERE dish_id = 4 |
| MERGE | DML | Inserts or updates in one statement | MERGE INTO menu USING new_prices ON … WHEN MATCHED THEN UPDATE … |
| SELECT | DQL | Reads rows | SELECT dish_name, price FROM menu WHERE category = ‘Biryani’ |
| GRANT | DCL | Gives a user a permission | GRANT SELECT ON menu TO analyst_user |
| REVOKE | DCL | Takes a permission away | REVOKE SELECT ON menu FROM analyst_user |
| COMMIT | TCL | Makes a transaction’s changes permanent | COMMIT |
| ROLLBACK | TCL | Undoes a transaction’s changes | ROLLBACK |
| SAVEPOINT | TCL | Marks a point to roll back to | SAVEPOINT before_discount |
DDL has its own detailed lesson, including the DROP versus TRUNCATE versus DELETE question that interviewers ask most: see DDL commands in SQL. The rest of this article focuses on the other four groups.
Walkthrough: one table through DML and DQL
Start with the menu table created above and four INSERT statements, one per dish. Prices are in rupees.
| dish_id | dish_name | category | price |
|---|---|---|---|
| 1 | Chicken Dum Biryani | Biryani | 329 |
| 2 | Paneer Biryani | Biryani | 279 |
| 3 | Mirchi ka Salan | Sides | 99 |
| 4 | Double ka Meetha | Dessert | 129 |
SELECT reads without changing anything. SELECT dish_name, price FROM menu WHERE category = ‘Biryani’ ORDER BY price DESC returns:
| dish_name | price |
|---|---|
| Chicken Dum Biryani | 329 |
| Paneer Biryani | 279 |
UPDATE changes values in the rows that match WHERE. The kitchen raises biryani prices by 20 rupees: UPDATE menu SET price = price + 20 WHERE category = ‘Biryani’. Two rows change:
| dish_id | dish_name | category | price |
|---|---|---|---|
| 1 | Chicken Dum Biryani | Biryani | 349 |
| 2 | Paneer Biryani | Biryani | 299 |
| 3 | Mirchi ka Salan | Sides | 99 |
| 4 | Double ka Meetha | Dessert | 129 |
DELETE removes the rows that match WHERE. The dessert is taken off the menu: DELETE FROM menu WHERE dish_id = 4. Three rows remain, and the table still exists, which is the difference from DROP.
| dish_id | dish_name | category | price |
|---|---|---|---|
| 1 | Chicken Dum Biryani | Biryani | 349 |
| 2 | Paneer Biryani | Biryani | 299 |
| 3 | Mirchi ka Salan | Sides | 99 |
The single most damaging mistake in all of SQL lives here: UPDATE or DELETE without a WHERE clause changes or removes every row in the table. Before you run either, run the same WHERE as a SELECT first and check the row count is what you expect.
TCL: undoing a mistake with ROLLBACK
Transactions are what make that mistake recoverable. Start a transaction, run your changes, look at the result, and only then decide to keep it or throw it away.
| Step | Statement | What it does |
|---|---|---|
| 1 | START TRANSACTION | Opens a transaction (BEGIN in PostgreSQL, BEGIN TRANSACTION in SQL Server) |
| 2 | UPDATE menu SET price = 0 | The mistake: every price is now 0, but only inside this transaction |
| 3 | SELECT * FROM menu | Shows three rows priced at 0, so you spot it |
| 4 | ROLLBACK | Discards everything since step 1 |
| 5 | SELECT * FROM menu | Prices are back to 349, 299 and 99 |
Had step 4 been COMMIT, the zeros would be permanent. SAVEPOINT lets you roll back part of a transaction: set SAVEPOINT before_discount, run a change, then ROLLBACK TO before_discount undoes only what came after the savepoint.
One catch that surprises people: most databases treat each statement as its own committed transaction unless you open one first. MySQL, PostgreSQL and SQL Server all work this way by default (called autocommit), so an UPDATE typed on its own is committed instantly and ROLLBACK has nothing to undo. Some desktop SQL tools switch autocommit off, so know which mode yours is in before you rely on ROLLBACK. DDL is different again: in MySQL and Oracle, a DROP or CREATE commits immediately even inside a transaction, so ROLLBACK will not bring back a dropped table. PostgreSQL and SQL Server can roll DDL back when it runs inside an explicit transaction.
DCL: who is allowed to do what
GRANT and REVOKE are usually a database administrator’s job, but analysts meet them when they ask for access. A typical setup gives analysts read-only rights:
| Statement | Effect |
|---|---|
| GRANT SELECT ON menu TO analyst_user | analyst_user can read the menu table |
| GRANT SELECT, INSERT ON menu TO ops_user | ops_user can read and add rows |
| REVOKE INSERT ON menu FROM ops_user | ops_user can read but no longer add rows |
If a query fails with “permission denied” or “SELECT command denied”, that is DCL at work, and the fix is a request to whoever administers the database, not a change to your SQL.
The SELECT clauses and operators analysts use daily
SELECT is one command, but it carries most of the language. These are the clauses and operators that make up nearly every analysis query, in the order they are written.
| Clause or operator | What it does | Example |
|---|---|---|
| SELECT DISTINCT | Returns unique rows only | SELECT DISTINCT category FROM menu |
| AS | Renames a column or table in the output | SELECT price AS price_inr FROM menu |
| FROM … JOIN … ON | Combines tables on a shared column | FROM orders o JOIN menu m ON o.dish_id = m.dish_id |
| WHERE | Filters rows | WHERE price > 200 |
| AND, OR, NOT | Combines conditions | WHERE category = ‘Biryani’ AND price < 300 |
| IN | Matches any value in a list | WHERE category IN (‘Biryani’, ‘Sides’) |
| BETWEEN | Matches a range, ends included | WHERE price BETWEEN 100 AND 300 |
| LIKE | Matches a text pattern; % means any characters | WHERE dish_name LIKE ‘%Biryani’ |
| IS NULL | Finds missing values (= NULL never works) | WHERE category IS NULL |
| GROUP BY | One row per group for aggregates | SELECT category, AVG(price) FROM menu GROUP BY category |
| HAVING | Filters groups | HAVING AVG(price) > 200 |
| ORDER BY | Sorts the result | ORDER BY price DESC |
| LIMIT | Keeps the first n rows | ORDER BY price DESC LIMIT 2 |
| UNION, UNION ALL | Stacks two results; UNION removes duplicates | SELECT dish_name FROM menu UNION SELECT dish_name FROM old_menu |
| CASE WHEN | If-then logic inside a query | CASE WHEN price > 300 THEN ‘Premium’ ELSE ‘Regular’ END |
The two that cause most beginner bugs are IS NULL (writing WHERE category = NULL returns nothing, because NULL is not equal to anything, including NULL) and LIMIT without ORDER BY (which returns some rows, not the top rows). Joins get their own lesson in our SQL joins guide, and the aggregate functions, GROUP BY and HAVING, CASE WHEN and window functions each have a lesson in this series.
Where MySQL, PostgreSQL and SQL Server differ
The command names are standard. Several everyday operations are written differently in each database, and these are the ones you will trip over first.
| Task | MySQL | PostgreSQL | SQL Server |
|---|---|---|---|
| First 2 rows | … ORDER BY price DESC LIMIT 2 | … LIMIT 2, or FETCH FIRST 2 ROWS ONLY | SELECT TOP 2 … ORDER BY price DESC |
| Start a transaction | START TRANSACTION | BEGIN | BEGIN TRANSACTION |
| Insert or update if exists | INSERT … ON DUPLICATE KEY UPDATE | INSERT … ON CONFLICT (dish_id) DO UPDATE, or MERGE from version 15 | MERGE |
| Rename a table | RENAME TABLE menu TO menu_items | ALTER TABLE menu RENAME TO menu_items | EXEC sp_rename ‘menu’, ‘menu_items’ |
| Auto-numbered key | INT AUTO_INCREMENT | INT GENERATED ALWAYS AS IDENTITY, or SERIAL | INT IDENTITY(1,1) |
| Join two strings | CONCAT(a, b) | a, two pipe characters, b; or CONCAT(a, b) | a + b, or CONCAT(a, b) |
| Today’s date | CURDATE() | CURRENT_DATE | CAST(GETDATE() AS DATE) |
| Can DDL be rolled back | No, it auto-commits | Yes, inside a transaction | Yes, inside an explicit transaction |
CONCAT works in all three, so it is the safe choice for joining text. The LIMIT versus TOP difference is the one interviewers use to check whether you have worked on more than one database.
How much of this a data analyst actually uses
Honestly, most of an analyst’s day is DQL: SELECT with joins, filters, grouping and window functions against tables someone else designed. DML comes up when you clean a staging table. DDL comes up when you build one. DCL and TCL you need to understand rather than write often, mainly so that a permissions error or an autocommit surprise does not cost you an afternoon.
That weighting is also how interviews for analyst roles are pitched. Expect one or two questions on command groups and DROP versus TRUNCATE versus DELETE, and most of the rest on SELECT. Our SQL interview questions follow the same split, and the data analyst interview questions show where SQL sits among the other rounds.
Frequently asked questions
What are the types of SQL commands?
SQL commands are grouped into five types: DDL for defining structure (CREATE, ALTER, DROP, TRUNCATE), DML for changing data (INSERT, UPDATE, DELETE), DQL for reading data (SELECT), DCL for permissions (GRANT, REVOKE) and TCL for transactions (COMMIT, ROLLBACK, SAVEPOINT). Some sources merge DQL into DML and list four types.
What is the difference between DDL and DML?
DDL commands change the structure of the database, such as creating a table or adding a column. DML commands change the data inside tables, such as inserting, updating or deleting rows. In MySQL and Oracle, DDL commits automatically and cannot be rolled back, while DML can be rolled back inside a transaction until it is committed.
Is SELECT a DML command?
It depends on the source. Many textbooks treat SELECT as DML, because it manipulates data in the sense of retrieving it. Others separate it into its own group, DQL, because it does not change anything. Both classifications are common, so mention both in an interview.
What is the difference between DELETE and TRUNCATE?
DELETE is a DML command that removes the rows matching a WHERE clause, or all rows if there is none, and can be rolled back inside a transaction. TRUNCATE is a DDL command that removes every row at once, is much faster on large tables, cannot take a WHERE clause, and cannot be rolled back in MySQL or Oracle (PostgreSQL and SQL Server can undo it inside an explicit transaction).
What is the difference between COMMIT and ROLLBACK?
COMMIT makes every change in the current transaction permanent and visible to other users. ROLLBACK discards every change made since the transaction began, returning the data to how it was. Once a transaction is committed, ROLLBACK can no longer undo it.
Which SQL commands should a data analyst learn first?
Start with SELECT and its clauses: WHERE, GROUP BY, HAVING, ORDER BY and joins, since they make up most analysis work. Then learn INSERT, UPDATE and DELETE for cleaning data, and CREATE and ALTER for building your own tables. GRANT, REVOKE and the transaction commands are worth understanding but are used less often by analysts.
Go from the commands list to real queries
A commands list tells you what exists. Writing a 40-line query that answers a business question correctly is a different skill, and it comes from practice on real data with someone checking your work.
SkilloVilla’s SQL: Beginner to Advanced course runs from the fundamental statements and creating databases through conditional logic, aggregation, joins and advanced SQL statements, taught in live classes with mentor support and practice on SQL playgrounds. For SQL inside a full analyst programme with Python and placement support, see the Data Analytics with Python track.