SQL > Constraint > NOT NULL Constraint

By default, a column can hold NULL. If you do not want to allow NULL value in a column, you will want to place the NOT NULL constraint on this column. The NOT NULL constraint specifies that NULL is not an allowable value.

The NOT NULL constraint ensures that a column always contains a value — any attempt to insert or update a row leaving that column empty will be rejected with an error.

For example, in the following statement,

CREATE TABLE Customer
(SID integer NOT NULL,
Last_Name varchar (30) NOT NULL,
First_Name varchar(30));

Columns "SID" and "Last_Name" cannot include NULL, while "First_Name" can include NULL.

An attempt to execute the following SQL statement,

INSERT INTO Customer (Last_Name, First_Name) VALUES ('Smith', 'Ken');

will result in an error because this will lead to column "SID" being NULL, which violates the NOT NULL constraint on that column.

Frequently Asked Questions

What does the NOT NULL constraint do in SQL?
NOT NULL prevents a column from accepting NULL values. Any INSERT or UPDATE statement that would result in a NULL in that column will fail with a constraint violation error.
Are columns NULL by default in SQL?
Yes. Unless you specify NOT NULL when creating a column, the column will accept NULL values by default.
Can I add NOT NULL to an existing table column?
Yes, you can use ALTER TABLE to add a NOT NULL constraint. However, you must ensure the column contains no existing NULL values before applying the constraint.
How does NOT NULL differ from a PRIMARY KEY?
A PRIMARY KEY implicitly adds both NOT NULL and UNIQUE constraints. A standalone NOT NULL constraint only prevents empty values — it does not enforce uniqueness.

Next: SQL DEFAULT Constraint

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact