Home > Net >  ERROR Column count doesn't match value count at row 1 something missed out
ERROR Column count doesn't match value count at row 1 something missed out

Time:11-07

    CREATE TABLE employee (
    emp_id INT PRIMARY KEY,
    first_name VARCHAR(40),
    last_name VARCHAR(25),
    birth_date DATE,
    sex VARCHAR(2),
    salary INT,
    super_id INT,
    branch_id INT 
);

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

and my problem is:

ERROR

"Column count doesn't match value count at row 1"

why i get this error? something missed out.

CodePudding user response:

You have several errors in your sintax:
Two fields must be nulleable and date must be yyyy-MM-dd

   CREATE TABLE employee (
    emp_id INT PRIMARY KEY,
    first_name VARCHAR(40),
    last_name VARCHAR(25),
    birth_date DATE,
    sex VARCHAR(2),
    salary INT,
    super_id INT NULL,
    branch_id INT NULL 
);

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

See it in action: http://sqlfiddle.com/#!9/2de42f

CodePudding user response:

Super_id and branch_id don't look nullable. Supply a value or make it nullable.

Also,

With insert statements it's good to explicitly write out columns.

Insert into <tablename> (<columnname>, ...) Values (<some value>,...)

CodePudding user response:

Your date is wrong.

In MySQL the date formaz has tp be yyyy-mm-dd so 1967-17-11 is not possible

    CREATE TABLE employee (
    emp_id INT PRIMARY KEY,
    first_name VARCHAR(40),
    last_name VARCHAR(25),
    birth_date DATE,
    sex VARCHAR(2),
    salary INT,
    super_id INT,
    branch_id INT 
);
INSERT INTO employee VALUES(100, 'David', 'Wallace', '1967-11-17', 'M', 250000, NULL, NULL);

db<>fiddle here

  • Related