CREATE TABLE defines a table; constraints reject data that breaks its rules. Our setup uses an integer primary key for unique identity, NOT NULL for required text, UNIQUE for distinct shelf labels, CHECK for positive page counts, and a foreign key to a shelf. SQLite permits multiple NULLs in a UNIQUE column; use NOT NULL as well when missing values are not allowed.
SQLite has storage classes NULL, INTEGER, REAL, TEXT, and BLOB (binary data). Ordinary column declarations have type affinity, not rigid typing: SQLite may convert values and may store other classes. STRICT tables impose stricter rules in recent SQLite versions. PostgreSQL generally enforces declared types more strictly. SQLite stores Boolean true and false as 1 and 0, so the setup’s CHECK limits published to those values. For money, integer minor units can avoid binary floating-point rounding, provided the currency and scale are clear.
A foreign key requires a matching parent key when non-NULL and enforcement is on. The nullable shelf allows an unassigned book. Schema constraints protect data regardless of which application writes it, but do not establish that every fact is true.
Read the pages definition in the setup as two separate choices: INTEGER gives the column integer affinity, while CHECK (pages > 0) rejects a false condition. In SQLite a CHECK result of NULL does not fail, so this rule permits unknown page counts; add NOT NULL if the value must also be present. A DEFAULT supplies a value when an INSERT omits that column; it does not replace an explicitly supplied NULL.
SQLite’s INTEGER PRIMARY KEY has special rowid behavior. Do not generalize that behavior to every primary-key declaration: SQLite has historical NULL exceptions for some other primary keys in ordinary tables. Explicit NOT NULL on each component, as in the association table later, makes the intent clear.