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:
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; |