MySQL SQL - 列计数与第 1 行的值计数不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10858228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:37:16  来源:igfitidea点击:

SQL - Column count doesn't match value count at row 1

mysqlcount

提问by Anonymous

I am trying to put this into the database. All rows are correct. Each row is also String/Text, except for "Id" which is an auto-incrementing Int value.

我正在尝试将其放入数据库中。所有行都是正确的。每行也是字符串/文本,除了“Id”是一个自动递增的 Int 值。

I am getting an unexpected error, however, saying Column count doesn't match value count at row 1. What is wrong with the query?

但是,我收到一个意外错误,说Column count 与 row 1 的 value count 不匹配。查询有什么问题?

INSERT INTO  `world2_main`.`Messages` (
`Id` ,
`ToId` ,
`FromId` ,
`Subject` ,
`Message` ,
`Read` ,
`Original Sender` ,
`Date`
)
VALUES (
NULL,  '3611',  '156',  'You are so...',  'Cool.',  '0',  '3611'  '1338590308');

回答by Rapha?l Althaus

well Id is an autoincrementing int value, and you put a null in it.

好吧,Id 是一个自动递增的 int 值,您在其中放置了一个 null。

Just do

做就是了

INSERT INTO  `world2_main`.`Messages` (
`ToId` ,
`FromId` ,
`Subject` ,
`Message` ,
`Read` ,
`Original Sender` ,
`Date`
)
VALUES (  '3611',  '156',  'You are so...',  'Cool.',  '0',  '3611'  '1338590308');

EDIT :in fact was just a missing comma after 3611. But avoiding inserting id is still good.

编辑:实际上只是在 3611 之后缺少一个逗号。但是避免插入 id 仍然很好。

INSERT INTO  `world2_main`.`Messages` (
    `ToId` ,
    `FromId` ,
    `Subject` ,
    `Message` ,
    `Read` ,
    `Original Sender` ,
    `Date`
    )
    VALUES (  '3611',  '156',  'You are so...',  'Cool.',  '0',  '3611',  '1338590308');

回答by Ngoni Mtanhaurwa

I have also discovered that if you have a trigger on the table you want to insert into and that trigger have another insert statement with un-matching columns and values, it will throw that error "Column count doesn't match value count at row ".

我还发现,如果您要插入的表上有一个触发器,并且该触发器有另一个带有不匹配列和值的插入语句,它将抛出该错误“列数与行的值数不匹配” .

回答by Vedha Peri

You may have defined different number of parameters and are probably passing a different number of parameters.

您可能定义了不同数量的参数,并且可能传递了不同数量的参数。

You may have:

你可能有:

INSERT INTO `buyers`(`key1`,  `key2` )
VALUES (value1,value2,value3 );

or more number of arguments in INSERT INTO than in the VALUES

或 INSERT INTO 中的参数数量多于 VALUES 中的参数数量

回答by Ojasv singh

Keep in mind 3 things:

请记住3件事:

  1. Number of parameters must match
  2. auto increment should be taken care of
  3. (This was my issue) When inserting multiple attributes
  1. 参数数量必须匹配
  2. 应注意自动增量
  3. (这是我的问题)插入多个属性时

don't do this--

不要这样做——

insert into agent(eid, ename, email, phone, score) values(
    (2, 'b', 'b', 5, 3),
    (1, 'a', 'a', 5, 3)
   );

You have to do this instead

你必须这样做

insert into agent(eid, ename, email, phone, score) values
    -> (1, 'a', 'a', 5, 3),
    -> (2, 'b', 'b', 5, 3);

Thanks

谢谢