Loading

MySQL NOT NULL Constraint

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

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

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;

Read Also:-

PRIMARY KEY CONSTRAINT
FOREIGN KEY CONSTRAINT
UNIQUE CONSTRAINT
CHECK CONSTRAINT
NOT NULL CONSTRAINT
DEFAULT CONSTRAINT
CREATE INDEX CONSTRAINT
AUTO_INCREMENT CONSTRAINT
INDEX CONSTRAINT
ENUM CONSTRAINT

For more detail about MySQL constraints please follow here

Share with:


One thought on “MySQL NOT NULL Constraint

Leave a Reply

Connect with:

z35W7z4v9z8w
Verified by ExactMetrics