4

I am just learning MySQL and am trying to create a basic table. But I am getting this error:

Error Code: 1136. Column count doesn't match value count at row 1.

Query is

insert into user(username,password,email,created,last_updated) values (
    ('TEST USERNAME','TEST PASSWORD','Test@test.com',current_timestamp(),current_timestamp()), 
    ('TEST USERNAME 2','TEST PASSWORD 2','Test2@test.com',current_timestamp(),current_timestamp())
);

The columns in the table are :

  • id
  • username
  • password
  • email
  • created
  • last_updated
domi27
  • 6,903
  • 2
  • 21
  • 33
Ashish Subedi
  • 53
  • 2
  • 6

2 Answers2

4

Remove the brackets for Values(..), i.e., it should be Values (..), (..) instead.

insert into user(username,password,email,created,last_updated) 
values
('TEST USERNAME','TEST PASSWORD','Test@test.com',current_timestamp(),current_timestamp()), 
('TEST USERNAME 2','TEST PASSWORD 2','Test2@test.com',current_timestamp(),current_timestamp());

From Docs, the syntax is:

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    [(col_name [, col_name] ...)]
    {VALUES | VALUE} (value_list) [, (value_list)] ...
    [ON DUPLICATE KEY UPDATE assignment_list]

...

INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of comma-separated column values, with lists enclosed within parentheses and separated by commas. Example:

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
0

your columns in your table has id yet you don't have it when you wrote

insert into user(username,password,email,created,last_updated)

you should write

insert into user(id,username,password,email,created,last_updated)
MartenCatcher
  • 2,713
  • 8
  • 26
  • 39