Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

NOT NULL

NOT NULL

The NOT NULL constraint mandates that a column must not accept NULL values, ensuring that you cannot insert or update a record without providing a value for this field.

The following SQL ensures that the “ID”, “LastName”, and “FirstName” columns will not accept NULL values:

Example

CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255) NOT NULL,
    Age int
); 

The following SQL adds a NOT NULL constraint to the “Age” column after the creation of the “Persons” table:

ALTER TABLE Persons
MODIFY Age int NOT NULL