Field | Type | Null | Key | Default | Extra
| Student_id | int | NO | PRI | NULL | auto_increment
As I need when I insert data in table its auto increment automatically insert value but when i try this query insert into student_info values("Harry",75,89,50,56);
I am getting this error as
ERROR 1136 (21S01): Column count doesn’t match value count at row 1
And when I write query like this
insert into student_info values(1,"Harry",75,89,50,56);
The data get inserted
I dont want to insert Student_id by manually as I have declared this column as AUTO_INCREMENT
Mysql Version 8.0
3
Answers
You just need to specify the list of columns explicitly in your query and omit the auto-incremented one. You haven’t specified which columns you have in your table, but it will be something like:
You need to write you request like that :
As you need to pass value to your id autoincrement, pass "empty" value, it will generate the new value by itself.
Specify the columns in the
INSERT
operation. For example:The database engine isn’t going to infer what you want based on whether the primary key is
AUTOINCREMENT
or not. It’s just looking for the number of values provided and the number of columns in the table. If those don’t match, you need to specify the columns you want to use.As an aside, you really should always specify the columns in these operations. Otherwise as soon as you change any table schema then operations which should still work won’t.