Not Null
ELI5 — The Vibe Check
NOT NULL is how you tell the database 'this field MUST have a value — you cannot leave it blank.' If you try to insert a row without it, the database throws a tantrum and refuses. Great for required fields.
Real Talk
NOT NULL is a column constraint that prevents NULL values from being stored in that column. When attempting to insert or update a row without providing a value for a NOT NULL column (and no DEFAULT is set), the database raises a constraint violation error.
Show Me The Code
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL, -- required
body TEXT -- optional (nullable)
);
When You'll Hear This
"The title column is NOT NULL so every post must have one." / "I got a NOT NULL constraint violation on the email field."
Related Terms
Column
A column is a category of data in a table. If a table is a spreadsheet, columns are the headers: 'Name', 'Email', 'Age'.
Default Value
A default value is what gets stored in a column when you do not provide one.
Table
A database table is exactly like a spreadsheet tab. It has columns across the top (name, email, age) and rows going down (one per person).
Unique Constraint
A unique constraint tells the database 'no two rows can have the same value in this column.