SQL Commands & Syntax Reference
100+ SQL commands organized into DDL, DML, DCL, TCL, clauses, JOINs, and aggregate functions — each with a one-line description.
DDL — Data Definition Language
Define and modify database schema structure.
| Command | Description |
|---|---|
CREATE TABLE | Create a new table |
CREATE DATABASE | Create a new database |
CREATE INDEX | Create an index on a column |
CREATE VIEW | Create a virtual table from a query |
ALTER TABLE | Modify an existing table structure |
ALTER COLUMN | Change column type or constraints |
DROP TABLE | Delete a table and all its data |
DROP DATABASE | Delete an entire database |
DROP INDEX | Remove an index |
TRUNCATE TABLE | Remove all rows without logging individual deletes |
RENAME TABLE | Rename a table |
ADD CONSTRAINT | Add a constraint to an existing column |
DML — Data Manipulation Language
Read and modify the data inside tables.
| Command | Description |
|---|---|
SELECT | Retrieve rows from one or more tables |
SELECT DISTINCT | Return unique values only |
INSERT INTO | Add new rows to a table |
INSERT INTO ... SELECT | Insert rows from a query result |
UPDATE | Modify existing rows |
DELETE FROM | Remove rows matching a condition |
MERGE | Upsert — insert or update based on a match |
REPLACE INTO | Delete + re-insert (MySQL) |
UPSERT | Insert or update on conflict (PostgreSQL) |
DCL — Data Control Language
Manage user permissions and access rights.
| Command | Description |
|---|---|
GRANT | Give user permission on a database object |
REVOKE | Remove a previously granted permission |
DENY | Explicitly block a permission (SQL Server) |
TCL — Transaction Control Language
Control the boundaries of database transactions.
| Command | Description |
|---|---|
BEGIN | Start a transaction block |
COMMIT | Save all changes in the current transaction |
ROLLBACK | Undo all changes since last commit |
SAVEPOINT | Set a named point to roll back to |
RELEASE SAVEPOINT | Remove a savepoint |
SET TRANSACTION | Configure isolation level |
Clauses & Operators
Shape and filter query results.
| Command | Description |
|---|---|
WHERE | Filter rows by condition |
AND / OR / NOT | Combine boolean conditions |
ORDER BY | Sort results ascending or descending |
GROUP BY | Aggregate rows sharing a column value |
HAVING | Filter groups after GROUP BY |
LIMIT / TOP | Restrict the number of returned rows |
OFFSET | Skip N rows (pagination) |
LIKE | Pattern match with wildcards (% and _) |
IN | Match against a list of values |
BETWEEN | Match a range of values |
IS NULL / IS NOT NULL | Check for null values |
EXISTS | True if subquery returns any row |
CASE WHEN | Conditional expression |
COALESCE | Return first non-null value in list |
NULLIF | Return null if two values are equal |
JOINs
Combine rows from multiple tables.
| Command | Description |
|---|---|
INNER JOIN | Return rows with matching keys in both tables |
LEFT JOIN | All left rows + matched right rows |
RIGHT JOIN | All right rows + matched left rows |
FULL OUTER JOIN | All rows from both tables |
CROSS JOIN | Cartesian product of both tables |
SELF JOIN | Join a table with itself |
Aggregate Functions
Compute summary values over groups of rows.
| Command | Description |
|---|---|
COUNT() | Number of matching rows |
SUM() | Total of a numeric column |
AVG() | Average of a numeric column |
MIN() | Smallest value in a column |
MAX() | Largest value in a column |
GROUP_CONCAT() | Concatenate values in a group |
Practice typing these in CodeSpeedTest →
SQL fluency comes from typing real queries until your fingers know the patterns. Start with SELECT and work your way through JOINs and window functions.
Frequently asked questions
What are the most important SQL commands?
SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE and DROP, plus clauses like WHERE, JOIN, GROUP BY and ORDER BY.
What is the difference between DDL and DML?
DDL (CREATE, ALTER, DROP) defines structure; DML (SELECT, INSERT, UPDATE, DELETE) works with the data itself.
Are SQL keywords case-sensitive?
No — SELECT and select are equivalent. Upper-case keywords are a readability convention.
Related language syntax references
- HTML Tags ReferenceAll semantic HTML5 elements organized by category — document structure, text, forms, media, and interactive elements.
- CSS Properties ReferenceEssential CSS properties grouped by category — layout, flexbox, grid, typography, colors, animations, and modern CSS features.
- React Interview Typing PracticeCore React patterns — hooks, component composition, state management — as typing drills for technical interviews.
- Java Syntax DrillJava keywords, OOP patterns, and collections framework reference. Practice typing Java code from Hello World to design patterns.
- C++ Syntax DrillModern C++ keywords, STL containers, smart pointers, templates, and lambdas — one compact reference for drilling C++ fluency.
- Linux Commands ReferenceEvery essential Linux command organized by category with common flags — navigation, files, processes, networking, and package managers.