WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL NOT NULL Constraint


By default, columns of a table accept NULL values.


SQL NOT NULL constraint

NOT NULL constraints force columns to not accept NULL values.

NOT NULL constraints force fields to always contain values. This means that you cannot insert new records or update records without adding values to the fields.

The following SQL forces the "ID" column, "LastName" column, and "FirstName" column to not accept NULL values:

Examples

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

Add NOT NULL constraint

Add a NOT NULL constraint to the "Age" field of an already created table as follows:

example

ALTER TABLE Persons MODIFY Age int NOT NULL;

Delete NOT NULL constraint

Removing the NOT NULL constraint in the "Age" field of an already created table looks like this:

Examples

ALTER TABLE Persons MODIFY Age int NULL;