[英]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.