MySQL的“列数与第1行的值数不匹配"是什么意思? [英] What does the MySQL mean by "Column count doesn't match value count at row 1"

查看:391
本文介绍了MySQL的“列数与第1行的值数不匹配"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我收到的消息

ER_WRONG_VALUE_COUNT_ON_ROW:列数与第1行的值数不符

ER_WRONG_VALUE_COUNT_ON_ROW: Column count doesn't match value count at row 1

这是我的全部代码.我的错误在哪里?

This is my whole code. Where is my mistake?

DROP TABLE student;

CREATE TABLE employee (
  emp_id INT PRIMARY KEY,
  first-name VARCHAR(40),
  birth_day DATE,
  sex VARCHAR(1),
  SALARY INT,
  super_id INT,
  branch_id INT
);

CREATE TABLE branch (
  branch_id INT PRIMARY KEY,
  branch_name VARCHAR(40),
  mgr_id INT,
  mgr_start_date DATE,
  FOREIGN KEY(mgr_id) REFERENCES employee(emp_id) ON DELETE SET NULL
);

CREATE TABLE works_with (
  emp_id INT,
  client_id INT,
  total_sales INT,
  PRIMARY KEY(emp_id, client_id),
  FOREIGN KEY(emp_id) REFERENCES employee(emp_id) ON DELETE CASCADE,
  FOREIGN KEY(client_id) REFERENCES client(client_id) ON DELETE CASCADE
);

-- Corporate
INSERT INTO employee VALUES(100, 'David', 'Wallace', '1967-11-17', 'M', 250000, NULL, NULL);

INSERT INTO branch VALUES(1, 'Corporate', 100, '2006-02-09');

UPDATE employee
SET branch_id = 1
WHERE employee_id = 100;

INSERT INTO employee VALUES(101, 'Jan', 'Levinson', '1961-05-11', 'F', 110000, 100, 1);

推荐答案

您的employee表具有7列,但是您要提供8个用于插入的值,这将生成您收到的错误消息.

Your employee table has 7 columns, but you are giving 8 values for insert, which generates the error message that you are getting.

一个好习惯是在语句中列出insert的列.这使这种类型的错误更容易发现,因为您无需回顾表的定义(如果将来在某个时刻向表中添加新列,它还可以防止查询失败-或删除现有列).

A good habit is to list the columns for insert in the statement. This makes this type of error much easier to spot, since you don't need to look back at the definition of the table (it also prevents your query from failing if you ever add new columns to the table at some point in the future - or drop existing columns).

INSERT INTO employee(emp_id, first_name, birth_day, sex, salary, super_id, branch_id)
VALUES(100, 'David', 'Wallace', '1967-11-17', 'M', 250000, NULL);

旁注:在employeecreate table语句中可以看到的未加引号的标识符first-name无效-因为它包含破折号(-).我认为这是一个错字,而您是指一个下划线(first_name).

Side note: unquoted identifier first-name, that can be seen in the create table statement for employee, is not valid - because it contains a dash (-). I assume that's a typo and you meant an underscore instead (first_name).

这篇关于MySQL的“列数与第1行的值数不匹配"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆