插入语句返回错误

时间:2017-03-28 13:22:06

标签: sql sql-server

运行以下代码时出错。    这是错误消息:"列名或提供的值数与表定义不匹配。"

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

有没有办法让下面的代码工作。

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

3 个答案:

答案 0 :(得分:10)

你必须像这样分开你的价值观:

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

每组值都应在括号中。

根据评论更新:

参考:

在sql server 2008之前,(在表值构造函数之前)

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

答案 1 :(得分:3)

像这样使用Insert语句:

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

OR

基于@SqlZim's回复评论:

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

答案 2 :(得分:0)

以下是实现插入的另一种方法:

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