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 |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: SQL NOT NULL Constraint
Post your Comment