SQL-Server-NOT-NULL-Constraints .

In this session i have discussed the SQL Server Not Null Constraints .

NOT NULL CONSTRAINT - This constraint not allow to insert the null value in a column

In my case i have set the not null for name and email column of table so no any one can insert the null value to name and email column of table .


NOT NULL Syntax .

The below code specify how to use the NOT NULL Constraints .

   CREATE TABLE tbl
   (
     id int ,
     name varchar(50) NOT NULL,
     email varchar(50) NOT NULL ,
     city varchar(50)
      
   )
   INSERT INTO tbl VALUES(1,null,'abc@gmail.com','Gorakhpur')
    

Output is

Cannot insert the value NULL into column 'name', table 'abc.dbo.tbl'; column does not allow nulls. INSERT fails.

The statement has been terminated.


Welcome to AndroidATPoint.

back image                     next image