Account
Categories

NOT NULL Constraint


The NOT NULL constraint is a type of constraint that is applied only to columns.

It checks whether a column contains any NULL values or not.

Here, a NULL value means a missing or unknown value.

If any attempt is made to insert a NULL value into that column, it will result in an error. for example: Suppose you define a column name as VARCHAR(100) NOT NULL.

This means every row must have a value in the name column — leaving it blank or inserting NULL will cause an error.

Syntax:

CREATE TABLE table_name (
    column_name data_type NOT NULL
);

Example:

CREATE TABLE Employees (
    employee_id INT PRIMARY KEY,
    name VARCHAR(100) NOT NULL
);


Note: In this example, the name column cannot have NULL values.
Every record must have a value for the name field.