简体   繁体   English

错误代码:1136。列计数与第 1 行的值计数不匹配,为什么?

[英]Error Code: 1136. Column count doesn't match value count at row 1 why?

USE Airline;

CREATE TABLE Responsible_for(
Time_work TIME NOT NULL,
date_work DATE NOT NULL,
Staff_ID INT NOT NULL,
Passenger_ID VARCHAR(45) NOT NULL,
 CONSTRAINT FOREIGN KEY(Passenger_ID) REFERENCES Passenger(Passenger_ID),
 CONSTRAINT FOREIGN KEY(Staff_ID) REFERENCES Staff(Staff_ID));

SELECT * FROM airline.Responsible_for;
INSERT INTO  Responsible_for VALUES(
    ('04:00:00','2019-04-01',1235,'1102546778'));

why there is error?为什么有错误? thank you谢谢你

You have an additional pair of parentheses around the list of values that should not be there.您在不应存在的值列表周围有一对额外的括号。

That should be:那应该是:

INSERT INTO Responsible_for(time_work, date_work, staff_id, passenger_id) 
VALUES ('04:00:00','2019-04-01',1235,'1102546778');

Notes:笔记:

  • it is a good practice to always enumerate the columns to insert ;总是枚举要insert的列是一个好习惯; this prevents hard-to-debug issues, and can make the code resilient to changes in the structure of the target table这可以防止难以调试的问题,并且可以使代码对目标表结构的变化具有弹性

  • you use airline at the beginning of the script, so there is no need to prefix the table name with the schema name in the insert statement您在脚本的开头use airline ,因此无需在insert语句中为表名加上模式名称前缀

  • I would recommend against storing the date and time components in separate columns;我建议不要将日期和时间组件存储在单独的列中; this makes things unnecessarily complicated (and less efficient) when you need to compare it against a datetime;当您需要将它与日期时间进行比较时,这会使事情变得不必要地复杂(并且效率降低); MySQL has the datetime datatype, that is meant to store both together MySQL 具有datetime数据类型,这意味着将两者存储在一起

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 游标在mysql中返回错误错误代码:1136。列计数与第1行的值计数不匹配 - cursor in mysql returns error Error Code: 1136. Column count doesn't match value count at row 1 mysql错误; 错误代码:1136。列计数与第1行的值计数不匹配 - mysql error; Error Code: 1136. Column count doesn't match value count at row 1 MySQL INSERT INTO 语句生成“错误代码:1136。列计数与行的值计数不匹配” - MySQL INSERT INTO statement generating “Error Code: 1136. Column count doesn't match value count at row” 错误代码:1136。列计数与第 1 行的值计数不匹配 - Error Code: 1136. Column count doesn't match value count at row 1 错误代码:1136。列计数与值计数不匹配 - Error Code: 1136. Column count doesn't match value count 错误代码:1136。在将向3个表中添加数据的过程中,列数与行1的值计数不匹配? - Error Code: 1136. Column count doesn't match value count at row 1 in a procedure which will add data in 3 tables? 错误代码:1136。列计数与第 1 行的值计数不匹配(我知道这是什么意思) - Error Code: 1136. Column count doesn't match value count at row 1 (I know what does it mean) 当我向表中添加新列时,插入开始失败,错误代码为:1136。列计数与第 1 行的值计数不匹配 - When I add a new column to my table, insert start failing with error Error Code: 1136. Column count doesn't match value count at row 1 尝试使用过程从另一个表中填充表的数据,错误代码:1136。列数与第 1 行的值计数不匹配不断弹出 - Trying to fill data of table from another table using a procedure, Error Code: 1136. Column count doesn't match value count at row 1 keeps popping up 错误1136:列计数与第1行的值计数不匹配 - ERROR 1136: Column count doesn't match value count at row 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM