How to Insert NULL Value into Table in SQL

In this article I am going to explain how to insert NULL value in a table.
  • 1631

Introduction

In this article I am going to explain how to insert NULL value in SQL. NULL keyword is used to insert NULL value in specific row.  We use NULL keyword in INSERT statement at place of value. 

If a column is define as NOT NULL at the time of table creation then we can't put null value in that column.

Statement that create a table with default value

create table mcnemp
(
id int default 0,
name varchar(15),
age int default 0 ,
city varchar(15),
salary money default 0
)

Statement that insert data in Table

insert into mcnemp values (1,'vipendra',22,'noida',10000)

insert into mcnemp values (2,'deepak',24,'lucknow',15000)

insert into mcnemp values (3,'rahul',20,'delhi',20000)

insert into mcnemp values (4,'rohit',21,'kanpur',12000)

insert into mcnemp values (5,'shiva',22,'greater noida',13000)

insert into mcnemp values (6,'shivam',18,'noida',14000)

insert into mcnemp values (7,'vip',17,'delhi',17000)

Statement show data in mcnemp table

Clipboard07.jpg

Statement that insert data in mcnemp table with NULL value

INSERT INTO dbo.mcnemp

        ( id, name, age, city, salary )

VALUES  ( 11,NULL,NULL,'delhi',NULL)

Other Statement that insert data in mcnemp table with NULL value

INSERT INTO dbo.mcnemp

        ( id, name)

VALUES  (12,'atul'

          )

Statement that show data in mcnemp after inserting NULL value

Clipboard02.jpg


© 2013 dotNetheaven. All rights reserved.