Loading

MySQL NOT NULL Constraint

A NULL value means no value on the data row. By default column of the table hold a NULL value.

NOT NULL Constraint enforce the column not accept a NULL value. It is a way to add another layer of validation of data.

MySQL NOT NULL Constraint avoids NULL value but It can accept the duplicate value.

The syntax for NOT NULL:-

column_name datatype NOT NULL

Example:-

CREATE TABLE Employee(

ID INT AUTO_INCREMENT PRIMARY KEY,

Name varchar(500) NOT NULL,

Department varchar(255),

);

NOT NULL for ALTER table:-

ALTER TABLE Employee MODIFY Department varchar(255) NOT NULL;

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w