learning-it by example

Back to the video

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

  1. 0:00 Eight rows, five of them bad. Without constraints, all eight got in.
  2. 0:36 The idea
  3. 1:07 Setup
  4. 1:33 The batch
  5. 2:05 Loose and checked tables
  6. 2:30 Loading, one row at a time
  7. 2:51 Asking the loose table
  8. 3:12 Run the loose tables
  9. 3:56 Three gaps and a fix
  10. 4:57 What this does not show
  11. 5:16 Mistakes to avoid
  12. 5:51 My take and next steps
  13. 6:22 Recap

Files

  • batch.py (13 lines)
  • run.py (53 lines)
  • schema.py (42 lines)

Download the code (zip)

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.