santhosha
santhosha

Reputation: 440

Insert into statement returning an error

I get the an error on running the below code. This is error message: "Column name or number of supplied values does not match table definition."

drop table employee
create table Employee (EmpID nvarchar(50) , EmpName nvarchar(50))
insert into Employee 
values('13','SANTHOSH','3','KARTHIK')

Are there any ways to make the below code work.

drop table employee
create table Employee (EmpID nvarchar(50) , EmpName nvarchar(50))
insert into Employee 
values('13','15','17'),('BLR','HYD','CHN')

Upvotes: 2

Views: 113

Answers (3)

RAJNIK PATEL
RAJNIK PATEL

Reputation: 1049

Use Insert statement like this way :

insert into Employee values('13','SANTHOSH'), ('3','KARTHIK')

OR

based from @SqlZim's answer comments :

insert into Employee values ('13','SANTHOSH')
insert into Employee values ('3','KARTHIK')

Upvotes: 3

Pawel Czapski
Pawel Czapski

Reputation: 1864

Below is another way to achive insert:

insert into Employee 
    (EmpID, EmpName)
values('13','SANTHOSH'),
    ('3','KARTHIK')

Upvotes: 0

SqlZim
SqlZim

Reputation: 38023

You have to separate your values like so:

drop table employee
create table Employee (EmpID nvarchar(50) , EmpName nvarchar(50))
insert into Employee
values('13','SANTHOSH') ,('3','KARTHIK')

Each set of values should be in parentheses.


Update based from comments:

Reference:

prior to sql server 2008, (prior to the table value constructor)

drop table employee
create table Employee (EmpID nvarchar(50) , EmpName nvarchar(50))
insert into Employee values ('13','SANTHOSH')
insert into Employee values ('3','KARTHIK')

Upvotes: 10

Related Questions