MySQL Tutorial
The NOT NULL constraint enforces a column to NOT accept NULL values.
The NOT NULL constraint enforces a field to always contain a value.
You cannot insert a new record, or update a record without adding a value to this field.
CREATE TABLE table_name
(
column1 data_type(size) NOT NULL,
column2 data_type(size) NOT NULL,
column3 data_type(size) NOT NULL,
....
);
The following MySQL ensures that the "ROLL_NO" and "NAME" columns will NOT accept NULL values when the "Students" table is created:
CREATE TABLE Students
(
ROLL_NO int(3) NOT NULL,
NAME varchar(20) NOT NULL,
SUBJECT varchar(20) ,
);
To create a NOT NULL constraint on the "SUBJECT" column when the "Students" table is already created, use the following SQL:
ALTER TABLE Students
MODIFY SUBJECT SUBJECT varchar(20) NOT NULL;