Italian Trulli

SQL NOT Null Constraint - How To use NOT NULL in SQL

Test Tribe
.

 NOT NULL Constraint in SQL - SQL NOT NULL Constraint

NOT Null Constraint is used when we need a column that can not hold any null value. while creating a table when we add a column with NOT Null Constraint then that column can not hold a null value.

Example - There is a student form if the developer defines the mobile number column of the student table as NOT Null value then the user has to enter the mobile number while adding and updating the user can not leave the field empty.

Syntax of NOT NULL 
Syntax of NOT NULL Constants is given below.

NOT Null on Create Table 

CREATE TABLE Student ( StdID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, StdAge int ); 

The above example of NOT Null Constraint ensures that the "StdID", "LastName", and "FirstName" columns will not value the user have to enter the value when the student table is created.

NOT Null on ALTER Table 


ALTER TABLE Student MODIFY Age int NOT NULL;


The above SQL query will change the Age column with the NOT NULL constraint of the student table. user can modify the constraint of an existing column.


Hope !!! The above Tutorial on NOT NULL Constraints is helpful for you...

Team,
QA acharya

Not null in SQL With Example

Post a Comment

0 Comments