Not Null in DBMS

Not Null in DBMS 

 

In this article, we will learn about Not Null in DBMS.

  • Null value is different from zero value or a field that contain spaces 
  • Null represents a record where data may be missing  data or data for that record may be optional 

NOT NULL Constraint 

  • Not all constraints prevents a column to contain null values 
  • Once not null is applied to a particular column, you cannot enter null values to that column and restricted to maintain  only some proper value other than null 
  • A not-null constraint cannot be applied at table level
Not Null in DBMS

Syntax

CREATE TABLE table_name
(
   column1 datatype(size),
   column2 datatype(size),
column3 datatype(size) NOT NULL ,
); 

Example 

CREATE TABLE STUDENT 
(
   ID   INT             NOT NULL,
   NAME VARCHAR (20)     NOT NULL,
   AGE  INT             NOT NULL,
   ADDRESS  CHAR (25) ,
   SALARY   DECIMAL (18, 2),       
   PRIMARY KEY (ID)
); 
  • In the above example, we have applied not null on three columns ID, name and age which means whenever a record is entered using insert statement all three columns should contain a value other than null
  • We have two other columns address and salary,  where not null is not applied which means that you can leave the row as empty or use null value while inserting the record into the table