Home > DeveloperSection > Forums > SQL NOT NULL Constraint
Ankit Singh

Total Post:341

Points:2389
Posted on    November-03-2015 10:00 PM

 .NET SQL Server 
Ratings:


 1 Reply(s)
 274  View(s)
Rate this:
what is   NOT NULL Constraint in sql server .


aditya kumar Patel

Total Post:245

Points:1743
Supported
Posted on    November-03-2015 10:15 PM

The NOT NULL constraint enforces a column to NOT accept NULL values.

The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field.

The following SQL enforces the "U_Id" column and the "LastName" column to not accept NULL values:

CREATE TABLE Users

(

U_Id int NOT NULL,

LastName varchar(255) NOT NULL,

FirstName varchar(255),

Address varchar(255),

City varchar(255)

)

--when we want insert null value lastname get error

insert into Users(U_Id,LastName,FirstName,Address,City)

 values(1011,null,'Ravi','mumbai','thane')

 

When I insert lastname null get error.

Result :


Don't want to miss updates? Please click the below button!

Follow MindStick