What does the MySQL mean by “Column count doesn't match value count at row 1”

前端 未结 1 689
自闭症患者
自闭症患者 2021-01-29 02:14

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

1条回答
  •  [愿得一人]
    2021-01-29 03:03

    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)
提交回复
热议问题