Lesson 24 of 30Article14 min
Data Types & Keywords Quick Reference
Pick types that match your data. Wrong types waste space or break math — storing scores as VARCHAR prevents AVG().
Data Types overview
Pick types that match your data. Wrong types waste space or break math — storing scores as VARCHAR prevents AVG().
Real-life example: Data types are choosing box sizes — letters go in envelopes, bricks need crates, not the other way around.
- INT / BIGINT — whole numbers (student_id, count)
- DECIMAL(p,s) — exact decimals (money, scores)
- VARCHAR(n) — text up to n characters (names, cities)
- DATE / DATETIME / TIMESTAMP — calendar and clock
- BOOLEAN — true/false flags (is_active)
Well-typed school schema snippet
CREATE TABLE students (
student_id INT PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
grade_level SMALLINT,
gpa DECIMAL(3, 2),
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Keywords quick reference
These words appear throughout SQL documentation and this course. They are reserved — avoid using them as table or column names.
Real-life example: Keywords are traffic signals — SELECT means go read, DELETE means stop and think twice.
- DDL: CREATE, ALTER, DROP, TRUNCATE
- DML: SELECT, INSERT, UPDATE, DELETE
- DCL: GRANT, REVOKE (permissions)
- Clauses: FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT
- Joins: INNER, LEFT, RIGHT, FULL, ON, UNION
- Logic: AND, OR, NOT, IN, BETWEEN, LIKE, EXISTS
One query using many keywords
SELECT c.course_name, AVG(e.score) AS avg_score
FROM enrollments e
INNER JOIN courses c ON e.course_id = c.course_id
WHERE e.score IS NOT NULL
GROUP BY c.course_name
HAVING AVG(e.score) > 75
ORDER BY avg_score DESC
LIMIT 10;