Skip to content

Integrity and Constraints (NULL, NOT NULL) ​

This page brings together referential integrity, which says an FK value must actually exist, and the NOT NULL constraint, which says a value must always be present.

Referential Integrity ​

This is the rule that "a child table's FK value must actually exist in the parent table." In SQLite, this check is off by default, so the rule only actually works if you turn on PRAGMA foreign_keys = ON; at the very top of every script. If you don't turn it on, a reel can be inserted even with a user_id that doesn't exist.

NULL and NOT NULL ​

NULL is not 0 or an empty string (''); it means "there is no value at all." If you put a NOT NULL constraint on a column, a row is saved only when that column has a value. For example, reels.video_url is NOT NULL, so a reel cannot be registered without a video URL.

Summary ​

ConceptKey point
Referential integrityA child's FK value must actually exist in the parent. In SQLite it works only after PRAGMA foreign_keys = ON;
NULLNot 0 or '', but "no value at all"
NOT NULLA row is saved only if the value is present (e.g. reels.video_url)

Source: Codyssey-B1/B6-1