Not Null Constraint in MySQL - MySQL Developer Tutorial

Not Null Constraint in MySQL

If you don't want to allow Null values in column of a table then you can create NOT NULL Constraint on Column in table.

Syntax :


Column_Name DataType NOT NULL;


Example :

Let's say we want to create customer table and we have column firstname and lastname and you want to defined them NOT NULL, you can use below script.


CREATE TABLE customer (
  `idcustomer` int(11) NOT NULL,
  `firstname` varchar(50) NOT NULL,
  `lastname` varchar(30) NOT NULL,
  `age` int(11)  NOT NULL ,
  `phonenumber` char(11)  NULL,
  `dob` date DEFAULT NULL,
  `gender` char(1) NOT NULL
  ) ;





What is Not Null in MySQL with Example - MySQL Developer Tutorial

No comments:

Post a Comment