π SQL Keywords List β DDL, DML, DQL, and TCL Explained
π§² Introduction β Why SQL Keywords Matter
SQL keywords are reserved words that form the foundation of all SQL queries. These keywords define structure, perform operations, and control logicβfrom creating tables to filtering, joining, and modifying data.
Whether you’re writing a basic SELECT or a complex stored procedure, mastering SQL keywords is essential for readable, maintainable, and powerful queries.
π― In this guide, youβll learn:
- Essential SQL keywords categorized by purpose
- Syntax examples and use cases
- Platform compatibility and keyword rules
- Reserved word handling and naming best practices
π 1. Core SQL Keywords (DQL β Data Query Language)
| Keyword | Description | Example |
|---|---|---|
SELECT | Retrieves data | SELECT * FROM employees; |
FROM | Specifies table | FROM users |
WHERE | Filters results | WHERE age > 25 |
ORDER BY | Sorts result set | ORDER BY salary DESC |
GROUP BY | Aggregates data | GROUP BY department |
HAVING | Filters grouped results | HAVING COUNT(*) > 2 |
DISTINCT | Removes duplicates | SELECT DISTINCT city FROM customers; |
LIMIT | Limits number of rows (MySQL, PostgreSQL) | LIMIT 10 |
TOP | Limits rows in SQL Server | SELECT TOP 5 * FROM orders; |
π§± 2. Data Definition Language (DDL) Keywords
| Keyword | Description | Example |
|---|---|---|
CREATE | Creates objects | CREATE TABLE users (...); |
DROP | Deletes objects | DROP TABLE orders; |
ALTER | Modifies structure | ALTER TABLE products ADD category_id; |
RENAME | Renames objects | ALTER TABLE old_name RENAME TO new_name; |
TRUNCATE | Deletes all rows (faster than DELETE) | TRUNCATE TABLE logs; |
π§ 3. Data Manipulation Language (DML) Keywords
| Keyword | Description | Example |
|---|---|---|
INSERT | Adds new rows | INSERT INTO users VALUES (...); |
UPDATE | Modifies existing rows | UPDATE users SET name = 'John'; |
DELETE | Removes rows | DELETE FROM users WHERE id = 3; |
VALUES | Specifies values in INSERT | VALUES ('Alice', 28) |
SET | Used in UPDATE or variable assignment | SET age = 30 |
π 4. Data Control Language (DCL) Keywords
| Keyword | Description | Example |
|---|---|---|
GRANT | Assigns privileges | GRANT SELECT ON employees TO analyst; |
REVOKE | Removes privileges | REVOKE INSERT ON orders FROM intern; |
πΎ 5. Transaction Control Language (TCL) Keywords
| Keyword | Description | Example |
|---|---|---|
BEGIN | Starts a transaction | BEGIN; |
COMMIT | Saves transaction | COMMIT; |
ROLLBACK | Undoes transaction | ROLLBACK; |
SAVEPOINT | Partial rollback point | SAVEPOINT before_update; |
π 6. SQL Operators and Conditional Keywords
| Keyword | Description | Example |
|---|---|---|
AND, OR, NOT | Logical operators | WHERE age > 25 AND city = 'NY' |
IN | Match from a list | WHERE id IN (1, 2, 3) |
BETWEEN | Match range | WHERE salary BETWEEN 30000 AND 60000 |
LIKE | Pattern matching | WHERE name LIKE 'J%' |
IS NULL | Checks for nulls | WHERE phone IS NULL |
CASE | Conditional logic | CASE WHEN score > 90 THEN 'A' ... END |
π§ 7. Advanced and Analytical SQL Keywords
| Keyword | Description | Example |
|---|---|---|
JOIN | Combines rows from multiple tables | INNER JOIN orders ON users.id = ... |
UNION | Merges two queries | SELECT ... UNION SELECT ... |
EXISTS | Checks for existence | WHERE EXISTS (SELECT 1 FROM ...) |
WITH | Defines CTE (Common Table Expression) | WITH cte AS (SELECT ...) |
WINDOW, OVER | Used in window functions | ROW_NUMBER() OVER (PARTITION BY ...) |
π‘οΈ 8. Reserved Words and Naming Rules
- Avoid using SQL keywords as column or table names (e.g.,
SELECT,USER) - If unavoidable, use quotes or brackets:
- PostgreSQL:
"user" - MySQL:
`user` - SQL Server:
[user]
- PostgreSQL:
π‘ Use snake_case or camelCase for custom names to improve readability.
π Summary β Recap & Learning Path
SQL keywords form the vocabulary of SQLβwithout them, there’s no query language. Knowing the purpose and proper use of each keyword ensures that your queries are both correct and optimized.
π Key Takeaways:
- SQL keywords are case-insensitive but usually written in UPPERCASE
- Reserved words should not be used as identifiers
- Learn keywords by function: DDL, DML, DCL, TCL, DQL
βοΈ Real-World Relevance:
Used in all forms of development: database schema design, ETL workflows, data reporting, application queries, and stored procedures.
β FAQ β SQL Keywords
β Are SQL keywords case-sensitive?
β
No. SELECT, select, and SeLeCt are treated the same. But convention prefers UPPERCASE for readability.
β Can I use a keyword as a column name?
β Yes, but you must escape it using double quotes, backticks, or brackets depending on your RDBMS.
β How can I view all reserved keywords?
- MySQL:
SHOW RESERVED WORDS; - PostgreSQL: Check system catalog or documentation
- SQL Server: Use sys.all_keywords or official doc
Share Now :
