skipnothing/SQL
UNIT 01

The Relational Model

Tables, rows, columns, keys, the shape of relational data

Before any query runs, the database needs a shape: tables of rows, columns with types, keys that link tables together. This unit grounds the model so every later command has something to act on.

Loading…
TOPICS
#1

Tables, Rows, Columns

Spot when a list of values should become a table, name the type of each column, and predict why row order and duplicates aren't guaranteed.

A CSV says Ada,ada@x.example,28, and a database asks back: what columns, what shape do these values fit? Once that's declared, the engine knows what to allow and what to reject, every row follows the same plan.

12 min
#2

Types & NULL

Pick a type for each column (text, integer, timestamp, boolean), predict what NULL does in comparisons, and decide when a column should allow NULL.

A blank-looking cell can mean three different things: 0, '', or no value at all. The database makes you commit up front, the column carries that decision into every comparison and count it ever sees.

12 min
#3

Primary & Foreign Keys

Choose between a surrogate and a natural primary key, draw the foreign-key arrow from child to parent, and pick what happens to children when the parent row is deleted.

Three rows sit in users: Ada, Brent, Cleo. An order arrives carrying user_id = 2, which user does it point at, and what stops one arriving with user_id = 99 for a user who doesn't exist?

13 min
#4

Normalization

Split a wide spreadsheet into 1NF/2NF/3NF tables by tracing three named bugs to the duplication that causes them, and decide when denormalizing back is a measured trade.

A fat orders sheet stores Ada's name and email on every order she places. Change her email on one row, her three rows disagree; delete the only T-Shirt order, the catalog forgets its price; one shape, three bugs.

14 min
UNLOCKS
All units