🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to SQL Notes
Topic #54

SQL Not Null


SQL NOT NULL Constraint

The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field.

By default, a column can hold NULL values.


NOT NULL on CREATE TABLE

To define a NOT NULL constraint when creating a table, add NOT NULL after the data type of the column name.

The following SQL creates a "Persons" table, and ensures that the "ID", "LastName", and "FirstName" columns cannot accept NULL values:

Example

  CREATE TABLE Persons (
    ID int NOT NULL,

  LastName varchar(255) NOT NULL,
    FirstName varchar(255)
  NOT NULL,
    Age int
);

NOT NULL on ALTER TABLE

To define a NOT NULL constraint on an existing table, use ALTER TABLE and add NOT NULL after the data type of the column name.

The following SQL adds a NOT NULL constraint on the "Age" column, after the "Persons" table is already created:

Syntax for SQL Server / MS Access:

ALTER TABLE Persons

ALTER COLUMN Age int NOT NULL;

Syntax for My SQL:

ALTER TABLE Persons

MODIFY COLUMN Age int NOT NULL;

Syntax for Oracle 10G+:

ALTER TABLE Persons

MODIFY Age int NOT NULL;

Remove a NOT NULL Constraint

To remove a NOT NULL constraint from a column (to let the column accept NULL values again), use the following syntax:

Syntax for SQL Server / MS Access:

ALTER TABLE Persons

ALTER COLUMN Age int NULL;

Syntax for My SQL:

ALTER TABLE Persons

MODIFY COLUMN Age int NULL;

Synatx for Oracle 10G+:

ALTER TABLE Persons

MODIFY Age int NULL;

Want to go beyond the notes?

Join CodingNow 2.0's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL Not Null – FAQs

Quick answers about learning SQL Not Null in SQL.

This free note from CodingNow 2.0 explains SQL Not Null in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on CodingNow 2.0, including SQL Not Null, is 100% free with no signup required.
With focused practice, most students grasp SQL Not Null in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now