×
>
<

DBMS

DBMS Constraint Not Null | CrackEase

Not Null in DBMS

Null vs NOT NULL

  • NULL is a special marker in SQL that indicates the absence of a value — it is different from zero or an empty string.
  • NULL typically means data is missing, unknown, or optional for that particular row and column.

NOT NULL Constraint

  • The NOT NULL constraint prevents a column from accepting NULL values. When applied, every inserted or updated row must provide a non-NULL value for that column.
  • Note: NOT NULL is specified on a column level (it cannot be applied as a table-level constraint in standard SQL syntax).

CREATE

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 this example ID, NAME and AGE are defined with NOT NULL. Every inserted row must supply values for these columns.
  • ADDRESS and SALARY are optional — they may contain NULL if no value is provided.
  • Applying NOT NULL improves data integrity by ensuring required attributes are always present.

Tip: If you need to add a NOT NULL constraint to an existing column, first ensure no NULL values exist (use an UPDATE to set defaults), then alter the column to NOT NULL. Different RDBMS have slightly different ALTER syntax.

Footer Content | CrackEase