What Is SQL?
SQL (Structured Query Language) is how you ask questions about data and change data in a relational database.
The key idea: SQL is declarative. You describe what you want, and the database figures out how to get it.
Core Concepts
SQL Is Declarative
In most programming languages you write step-by-step instructions. In SQL, you define the desired result.
flowchart LR
A[You write SQL] --> B[SQLite parses it]
B --> C[SQLite plans it]
C --> D[SQLite executes it]
D --> E[Result rows + columns]
Common SQL Statement Families
You'll see these categories throughout the course:
| Category | What it does | Examples |
|---|---|---|
| Querying | Reads data | SELECT |
| Data change | Inserts/updates/deletes data | INSERT, UPDATE, DELETE |
| Schema | Defines tables and indexes | CREATE TABLE, CREATE INDEX |
| Transactions | Groups changes as one unit | BEGIN, COMMIT, ROLLBACK |
Code Examples
-- A SELECT statement returns a result set (rows and columns).
-- Here we return one row with two columns.
SELECT
2 + 2 AS answer,
'SQL is declarative' AS note;
| answer | note |
|---|---|
| 4 | SQL is declarative |
-- SQL can use expressions and built-in functions.
-- This example is deterministic and does not require any tables.
SELECT length('SQLite') AS letters;
| letters |
|---|
| 6 |
SQLite-Specific Nuances
SQLite supports a large, practical subset of SQL, but every database has its own dialect edges.
When you see differences between SQLite and other databases in this course, they are usually about typing, concurrency, and certain DDL details.
Common Pitfalls / Best Practices
Assuming rows come back in a consistent order without an explicit sort.
Unless you use ORDER BY (covered later), the database is free to return rows in any order.
Treat SQL like code:
- Format it for readability
- Use clear names
- Keep queries small and test them often
Quick Challenge
Write a query that returns one row with three columns:
topicasSQLlevelasbeginnerreadyas1
View Solution
-- Literals are a great way to practice the shape of a result set.
SELECT
'SQL' AS topic,
'beginner' AS level,
1 AS ready;
| topic | level | ready |
|---|---|---|
| SQL | beginner | 1 |