Skip to main content

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:

CategoryWhat it doesExamples
QueryingReads dataSELECT
Data changeInserts/updates/deletes dataINSERT, UPDATE, DELETE
SchemaDefines tables and indexesCREATE TABLE, CREATE INDEX
TransactionsGroups changes as one unitBEGIN, 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;
answernote
4SQL 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 Nuance

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

Pitfall

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.

Best Practice

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:

  • topic as SQL
  • level as beginner
  • ready as 1
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;
topiclevelready
SQLbeginner1