---
title: "Inserting into table with a Default column value"  
description: "Inserting into table with a Default column value"  
author: "Anonymous User"  
published: 2013-05-04  
updated: 2013-05-04  
canonical: https://www.mindstick.com/forum/813/inserting-into-table-with-a-default-column-value  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 2 minutes  

---

# Inserting into table with a Default column value

Hi Everyone!\
I have created a table with a [default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources) [column value](https://www.mindstick.com/forum/161178/how-to-delete-duplicate-rows-based-on-single-column-value-in-mssql) male\
[CREATE TABLE](https://www.mindstick.com/articles/443/how-to-create-table-in-sql-server) Persons (name [varchar](https://www.mindstick.com/forum/161878/what-is-the-difference-between-nvarchar-and-varchar)(20), age int, sex varchar(5) default 'male')[Insert statement](https://www.mindstick.com/forum/157532/why-is-use-the-identity-column-in-the-insert-statement-in-sql) #1:\
INSERT INTO Persons values('Bob', 20)Insert statement #2:\
INSERT INTO Persons(name,sex) values('Bob', 20)When I try to insert the values into Persons table using the insert statement #1, I get the error shown below\
[column name](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) or number of supplied values does not match table [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat)\
But when I insert into Persons using statement #2, it successfully executes.\
Can some [please explain](https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true) why this happens?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi!\
Well, in your statement #1, if you omit the list of columns, you must supply values for all three columns, and you're not doing that. That's why it fails if you provide only two of those values.\
And your statement #2 should probably be:\
INSERT INTO Persons(name, age) values('Bob', 20)and then you're clearly specifying which columns to insert into (name and age) and you're providing the two values required to fill two columns - that's why it works. The third column will be filled with the configured default, since you didn't specify anything for it.\
For these reasons, I would recommend to always explicitly specify the list of columns you want to insert data into - don't just omit that list and assume that you're getting all columns right...


---

Original Source: https://www.mindstick.com/forum/813/inserting-into-table-with-a-default-column-value

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
