Constraints That Catch Bad Data: PK, FK, CHECK
Without constraints SQLite loaded all 8 rows, 5 of them bad; with constraints only 3 got in.
Video #254 ยท Data modelling
Steps in the video
- 0:00 Eight rows, five of them bad. Without constraints, all eight got in.
- 0:36 The idea
- 1:07 Setup
- 1:33 The batch
- 2:05 Loose and checked tables
- 2:30 Loading, one row at a time
- 2:51 Asking the loose table
- 3:12 Run the loose tables
- 3:56 Three gaps and a fix
- 4:57 What this does not show
- 5:16 Mistakes to avoid
- 5:51 My take and next steps
- 6:22 Recap
Files
- batch.py (13 lines)
- run.py (53 lines)
- schema.py (42 lines)
Tested with
Python 3.12.15
What this does not show
Eight made-up orders in SQLite only; no load cost is measured and rejected rows are printed, not stored.
Sources
Learning IT by Example.