Reputation: 61
Need help how to solve this problem... I have created a users table which has following columns
Create table users
(
uid int(10) PRIMARY KEY AUTO_INCREMENT,
uname varchar(50),
password varchar(50),
email varchar(50)
);
when i insert values with uid
it executes successfully :
Insert into users values(1,'ABC','Helloworld','[email protected]');
but when i try without uid
Insert into users values('SDC','Helloworld','[email protected]');
it does not execute successfully and gives an error
ERROR 1136 (21S01): Column count doesn't match value count at row 1
my uid
has AUTO_INCREMENT
so it should automatically increase..
Upvotes: 3
Views: 10716
Reputation: 1271003
Of course auto_increment
is working correctly. You just need to learn best practices about using insert
. Always list all the columns (unless you really, really know what you are doing):
Insert into users (uname, password, email)
values('SDC', 'Helloworld', '[email protected]');
The id column will be auto-incremented. If you don't list the columns, then MySQL expects values for all columns, including the auto-incremented one.
Upvotes: 5