Home Sql SQL NOT NULL Constraint
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

SQL NOT NULL Constraint

Advertisement
The NOT NULL constraint allows a column not to accept NULL values. This specify that NOT NULL Constraint enforce the field to accept a value.

SQL NOT NULL Constraint

     

The NOT NULL constraint allows a column not to accept NULL values. This specify that NOT NULL Constraint enforce the field to accept a value. Simply, neither you insert or update a new record without  adding a value to this field.

Understand with Example

The Tutorial illustrates an example from 'SQL NOT NULL Constraint'. In this example, we create a table Stu_Class_10 with the help of create statement. When you create a table ,we define a field attribute, data type, null value etc. The following SQL enforces the Columns "Stu_Id","Stu_Name" and "Stu_Class" column not to accept NULL values. The insert into adds the records value into table'Stu_Class_10'.The select statement show you the records from table 'Stu_Class_10'.When you do not insert any value to record ,the records shows you SQL NOT NULL Constraint.

Create Table Stu_Class_10

CREATE TABLE Stu_Class_10(
Stu_Id integer(2) NOT NULL, 
Stu_Name varchar(15) NOT NULL, 
Stu_Class  varchar(10)) NOT NULL)

Insert data into Stu_Class_10 table

insert into Stu_Class_10 values(1,'Komal',10);
insert into Stu_Class_10 values(2,'Ajay',10);
insert into Stu_Class_10 values(3,'Rakesh',10);
insert into Stu_Class_10 values(4,'Bhanu',10);
insert into Stu_Class_10 values(5,'Santosh',10);

Stu_Class_10

Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2008

Ask Questions?    Discuss: SQL NOT NULL Constraint  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com