×
☰ See All Chapters

Not null and null constraint in MySQL

The NOT NULL modifier prevents NULL (a token (non-zero) that designates a column as being empty) values from appearing in the column. NULL allows null values. Example every persons will not be having PHONE for which we can use NULL constraint.

Syntax to create table with not null and null constraint in MYSQL

CREATE TABLE <table-name>

(

<column-name1> <data-type(size)> NOT NULL,

<column-name2> <data-type(size)> NULL

);

Example to create table with not null and null constraint in MYSQL

CREATE TABLE CUSTOMER

(

CUSTOMER_ID INT NOT NULL,

PHONE  NUMERIC(10)  NULL

);

 

 

 

 

 

 

 


All Chapters
Author