NOT NULL

SQL NOT NULL Constraint

By default a column can hold NULL. NOT NULL forces the column to always have a value, so you cannot insert a row or update it without one.

CREATE TABLE Persons (
    ID        INT NOT NULL,
    LastName  VARCHAR(255) NOT NULL,
    FirstName VARCHAR(255) NOT NULL,
    Age       INT
);

What Happens on Violation

INSERT INTO Customers (CustomerID, CustomerName) VALUES (20, NULL);
-- Error: NOT NULL constraint failed: Customers.CustomerName

NOT NULL on ALTER TABLE

-- MySQL
ALTER TABLE Persons MODIFY COLUMN Age INT NOT NULL;
-- SQL Server
ALTER TABLE Persons ALTER COLUMN Age INT NOT NULL;
-- PostgreSQL
ALTER TABLE Persons ALTER COLUMN Age SET NOT NULL;

Note: Adding NOT NULL fails if existing rows already contain NULL. Update those rows first.