A NOT NULL constraint requires a column to contain a value instead of SQL NULL. It protects data integrity by rejecting writes that omit a required value. section 2.3.1
Require catalog fields
CREATE TABLE products.catalog (\n id SERIAL PRIMARY KEY,\n name VARCHAR(100) NOT NULL,\n description TEXT NOT NULL,\n category TEXT,\n price NUMERIC(10, 2)\n);\n\nThe catalog requires both name and description, while category and price remain nullable. Inspect the result with \\d products.catalog; psql reports name and description as “not null.”
Add the constraint later
ALTER TABLE products.reviews\n ALTER COLUMN review SET NOT NULL,\n ADD CONSTRAINT review_rank_check CHECK (rank BETWEEN 1 AND 5);\n\nDefine required constraints during CREATE TABLE when they are known; use ALTER TABLE when strengthening an existing design. section 2.3.1





