NOT NULL Constraint
A column may by default contain NULL values. Therefore, a NOT NULL constraint is utilized in order to solve this problem when necessary. This constraint states that there can never be a blank cell value for any row in this column. Typically, this condition is applied to columns that store data that is extremely necessary to locate and retrieve from a table. The NOT NULL constraint can be set up either when the table is first created or at a later time using a MODIFY statement. Below, we can see the syntax for declaring a NOT NULL Constraint on the Customer_ID column during the creation of the table, named Customer:
1CREATE TABLE Customer (
2 Customer_Id int NOT NULL
3);
The int keyword stands for integer – which means that the fields of this column only accept integer values. In case we had created the table without specifying the NOT NULL constraint and would like to add it at a later time, we can do this by using the ALTER and MODIFY keywords, like so:
1ALTER TABLE Customer
2MODIFY Customer_Id int NOT NULL;