pradyu pradyu - 7 months ago 15
SQL Question

mysql table not accepting one auto increment and one default column

am trying to create a sample table with one auto increment and one default column, but mysql is throwing "Incorrect table Definition; there can only be one auto column and it should be defined as key".

the table am using is shown below:

create table dummy
(invno int NOT NULL AUTO_INCREMENT,
candidate varchar(50) default '000',
client varchar(20) );

thanks in advance:)

Answer

The error is already giving you the answer, your auto increment must be a key.

So the solution is:

create table dummy (invno int NOT NULL AUTO_INCREMENT PRIMARY KEY, candidate varchar(50) default '000', client varchar(20) );