How to Insert Default Value in SQL

In this article I am going to explain how to insert default value in SQL.
  • 2114

Introduction

In this article I am going to explain how to insert default value in SQL. DEFAULT keyword is used to insert default value in specific row. To insert default value in specific column, column must be define as default column.

We use DEFAULT keyword in INSERT statement at place of value. 

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

Clipboard05.jpg

Statement that insert data in mcnemp table with default value

insert into mcnemp values (9,'reena',default,default,default)
insert into mcnemp values (default,'seena',default,default,default)

Statement that show data in mcnemp after inserting default value

Clipboard07.jpg


© 2019 DotNetHeaven. All rights reserved.