mysql列数与行数不匹配,MySQL的“列数与第1行的值数不匹配”是什么意思?

This is the message I'm getting

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);

解决方案

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

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);

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值