MySQL 错误 1136:列计数与第 1 行的值计数不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9798411/
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
MySQL Error 1136:Column count does not match value count at row 1
提问by kmaz13
DROP TABLE IF EXISTS student;
CREATE TABLE student(
bannerid VARCHAR(9) PRIMARY KEY NOT NULL ,
lastname VARCHAR(45) NOT NULL ,
firstname VARCHAR(45) NOT NULL ,
major VARCHAR(45) NOT NULL DEFAULT 'undeclared' ,
gpa DECIMAL(2) NOT NULL DEFAULT 0.00 ,
age INT NOT NULL DEFAULT 18 );
INSERT INTO student VALUES ('b00001111', 'smith', 'fred', 'computer science', 3.12, 20);
INSERT INTO student VALUES ('b00002222', 'jones', 'herb', 'computer science', 2.00, 19);
INSERT INTO student VALUES ('b00003333', 'chan', 'Hymanie', 'computer information systems', 3.50, 50);
INSERT INTO student VALUES ('b00004444', 'baker', 'al');
INSERT INTO student VALUES ('b00005555', 'booker', 'sue');
This results in the following error and I do not understand why. I want the last two INSERTs to use the default values.
这导致以下错误,我不明白为什么。我希望最后两个 INSERT 使用默认值。
MySQL Error 1136:Column count does not match value count at row 1
MySQL 错误 1136:列计数与第 1 行的值计数不匹配
回答by Rocky
In the insert statement you need to specify the column names explicitly for the values that are being passed , you can ignore the column names if you are passing all the column values. So your last two statements should be
在插入语句中,您需要为正在传递的值明确指定列名,如果您正在传递所有列值,则可以忽略列名。所以你的最后两个陈述应该是
INSERT INTO student (bannerid,lastname,firstname) VALUES ('b00004444', 'baker', 'al');
INSERT INTO student (bannerid,lastname,firstname) VALUES ('b00005555', 'booker', 'sue');