0PricingLogin
SQL Academy · Lesson

NOT NULL and CHECK Constraints

Forbid missing values with NOT NULL and validate domain rules with CHECK (price > 0, status IN ('active','archived')).

Why Constraints?

Constraints push validation INTO the database. The benefit is huge: every app, script, and ad-hoc query writes valid data — or fails loudly.

NOT NULL

The simplest constraint: this column must have a value:

CREATE TABLE users (
  id    BIGSERIAL PRIMARY KEY,
  email VARCHAR(255) NOT NULL,
  age   INT                                  -- NULL allowed
);

All lessons in this course

  1. NOT NULL and CHECK Constraints
  2. UNIQUE Constraints and Composite Keys
  3. FOREIGN KEY and Referential Actions
  4. DEFAULT Values and Generated Columns
← Back to SQL Academy