Data that keeps its own rules
Relational databases and SQL
From spreadsheet to database
Tables, types, rules and questions for the Walk Office
Who enforces the rules?
Spreadsheet
- Any cell takes anything
- Two editors overwrite each other
- Rules live in people's heads
Relational database
- Every column has a type
- Constraints refuse bad rows
- Changes are all or nothing
UPDATE 6
the command tag when a price change for one walk forgot its WHERE clause
Check first, then commit
- SELECT with the WHERE you plan to use
- BEGIN
- UPDATE or DELETE with the same WHERE
- Read the count, then COMMIT or ROLLBACK
Aisha has no phone number recorded. Which query finds her?
- WHERE phone = NULL
- WHERE phone IS NULL
- WHERE phone = ''
Show the answer
NULL means unknown, so comparing it with = is never true. IS NULL is the test that works. An empty string is a value, not a missing one.
Never store rand in floating point. Store moments as timestamptz, in the Africa/Johannesburg zone.
Now watch the video
Watch how WHERE chooses rows, why text needs single quotes, and how UPDATE and DELETE change only what you mean.
Watch the video