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