Advertisement
Google Ad Slot: content-top
MySQL Not Null
MySQL NOT NULL Constraint
The NOT NULL constraint in MySQL ensures that a column cannot store NULL values. It is used when you want to ensure that a column always contains a value and cannot be left empty.
NOT NULL on CREATE TABLE
Syntax:
CREATE TABLE table_name ( column1 data_type NOT NULL, column2 data_type, column3 data_type NOT NULL );
Example
Explanation:
nameandagecannot beNULL.emailcan acceptNULLvalues.
NOT NULL on ALTER TABLE
Syntax:
ALTER TABLE table_name MODIFY column_name data_type NOT NULL;
Example:
Explanation:
- This makes the
emailcolumn mandatory, ensuring it cannot storeNULLvalues.