SQL for BAs: statement types, keys and constraints
Know the five families of SQL statements, the difference between a primary key and a unique key, and the rules a database enforces on its own.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: filing-cabinet rules. Someone builds the drawers. Someone files folders and takes them out. A manager decides who gets a key. A clerk says the day's moves are finished, or undoes them.
Daily List is a made-up to-do app (SYNTHETIC / TRAINING ONLY). The team plans a reminders table. Sam, the , wants to know which family each statement belongs to, because each family carries a different risk.
What it is: (Structured Query Language) is the language a database understands. A table is a grid of rows and columns. Statements fall into groups by what they do. An is one of those families: defining tables, changing rows, reading rows, granting access, or saving and undoing a batch. A primary key is the column that picks out exactly one row and is not NULL. A database constraint is a rule the database applies on its own, such as "this cannot be empty". DELETE removes chosen rows. TRUNCATE empties a table and keeps it. DROP removes the table. Those three are the neighbours people mix up.
Why it matters: A SELECT only looks. An UPDATE with no WHERE rewrites every row. A DROP removes the drawer and everything in it. Sam asks which family a change belongs to before anyone runs it.
The five names are a teaching list. Real products blur the edges a little.
PLAIN WORDS · 2 in this section
- constraint
- a limit or rule that restricts what can be done
- empties
- becomes empty, or drains into somewhere else
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the work.
THE REAL JOB The picture helps a newcomer remember the five families of statements and that a key picks out one row while a constraint is a rule the database enforces.
- Build the table
- Fill it with rows
- Look at the rows
- Lock who may enter
- Confirm or undo
HOW THE PICTURE MAPS
| In the picture | In the work |
|---|---|
| Building the drawers | Data definition |
| Filing and removing folders | Data manipulation |
| Looking inside a drawer | Data query |
| Handing out keys to the room | Data control |
| Saying "all done" or "undo it" | Transaction control |
WHERE THIS PICTURE STOPS
- A cabinet is fixed once built, but a table can be rebuilt with one command.
- A paper folder has one place. A row can be copied into other tables.
- A manager sees who opened a drawer, but the database must be told to log it.
HOOK
Build, fill, look, lock, confirm.
REMEMBER IT THIS WAY
A contrast: two neighbours told apart by one test.
Ask of any statement: does it build the drawers, move the folders, or only look inside?
| In the trick | What it stands for |
|---|---|
| build the drawers | Building the drawers is definition |
| move the folders | Filing and removing folders is manipulation |
| look inside | Looking inside is query |
TELL A FRIEND
Structured Query Language () statements fall into five families by what they do, and a picks out one row. A constraint is a rule the database enforces by itself.
OFTEN MIXED UP WITH SQL for BAs: SELECT and WHERE. That topic teaches how to read rows with SELECT and WHERE. This one names all five families and the rules inside a table.
PRACTISE AND KEEP
Sources for this topic — 6 sources
- Market practice
Constraints (PostgreSQL documentation, data definition chapter) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, §5.5 CHECK/NOT NULL/UNIQUE/primary/foreign keys; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: §5.5 CHECK/NOT NULL/UNIQUE/primary/foreign keys. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
SQLite: CREATE TABLE ↗ — SQLite project · SQLite: CREATE TABLE; DEFAULT/NOT NULL/CHECK, primary-key legacy NULL exceptions. Publisher page opened6November 2026.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
- Market practice
SQLite: foreign-key support ↗ — SQLite project · SQLite: foreign-key support; Connection-level enabling and referenced/referencing constraints. Publisher page opened6November 2026.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
- Market practice
Statements that cause an implicit commit (MySQL reference manual) ↗ — Oracle / MySQL · MySQL 8.4 publisher manual opened6November 2026. §15.3.3 DDL statements that implicitly commit; no claim all database DDL behaves alike.
MySQL8.4 publisher manual opened6November2026. §15.3.3 DDL statements that implicitly commit; no claim all database DDL behaves alike.
- Market practice
TRUNCATE (PostgreSQL documentation) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, TRUNCATE transactional and locking behavior; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: TRUNCATE transactional and locking behavior. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Simplified educational illustration
Payments Signal editorial teaching models — Payments Signal
What this simplifies: Daily List people, data and exercises are invented for teaching. Query results belong to the declared fixture and database version. Authorization, business identity, time bounds and unknown-value policy must be agreed in context; no universal mandatory query template is implied.
Used wherever diagrams, scenarios, figures, or example values are didactic constructions rather than sourced facts; every such use carries a simplifications disclosure. All people, companies, banks, and list entries in examples are fictional.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.