SQL NOT NULL CONSTRAINT

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 540  View(s)
Ratings:
Rate this:
what is   NOT NULL Constraint in sql server .
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: SQL NOT NULL Constraint

    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 :

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!