SQL Tutorial 0/85 lessons ~6 min read Lesson 3
What is SQL?
SQL — Structured Query Language — is a declarative language for talking to relational databases.
Course progress0%
Focus
6 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
SQL — Structured Query Language — is a declarative language for talking to relational databases. Instead of writing loops to find data, you describe what you want and the database figures out how to fetch it efficiently.
Beginner analogy: imperative code is like giving turn-by-turn directions. SQL is like saying 'take me to the airport' — the optimizer picks the best route.
Understanding the topic
Core concepts to understand:
- SQL is declarative: you describe results, not steps.
- Standard since 1986 (SQL-86) — every relational DB speaks it.
- Sub-languages: DDL (CREATE/ALTER), DML (INSERT/UPDATE), DQL (SELECT), DCL (GRANT), TCL (COMMIT).
- Each DB adds dialect features — Postgres has JSONB, MySQL has fulltext, etc.
- SQL is read by an optimizer that picks the cheapest plan.
Syntax reference
Visual workflow / architecture:
bash
SQL Statement│▼┌────────────┐│ Parser │ → AST└─────┬──────┘▼┌────────────┐│ Planner │ → logical plan└─────┬──────┘▼┌────────────┐│ Optimizer │ → physical plan (cheapest)└─────┬──────┘▼┌────────────┐│ Executor │ → rows└────────────┘
Real-world use
When Amazon shows you 'orders in last 30 days', it runs a SQL query that the optimizer evaluates against billions of rows in milliseconds using indexes.
Best practices
- Write SQL that is readable first; performant second.
- Use uppercase keywords (
SELECT) and lowercase identifiers — convention. - Prefer ANSI-standard SQL when possible for portability.
Hands-on exercise
Interview preparation — practice these questions:
- Q1. What does SQL stand for?
- Q2. Difference between DDL, DML and DQL.
- Q3. Is SQL declarative or imperative?
- Q4. What does the query optimizer do?
- Q5. Name three SQL dialects.
Ready to mark this lesson complete?Track your journey across the entire course.