MySQL - INCORRECT TABLE DEFINITION,THERE CAN ONLY BE ONE AUTO COLUMN .......

Asked By N on 25-Nov-10 08:58 PM
Hi all,

Table Name : Users
user_id int not null auto_increment
name varchar(40) not null
admission_no varchar(8) not null
password varchar(20) not null
email varchar(60)not null

I want my email to be the primary key so i typed this on mysql;

Create table users(user_id int not null auto_increment,name varchar(40) not null,admission_no varchar(8) not null,password varchar(20) not null,email varchar(60) not null,Primary Key(email));

Apparently , it showed this instead : Incorrect table definition, there can only be one auto column and it must be defined as a key.

How do i solve this. Really need help on this.

Venkat K replied to N on 25-Nov-10 09:20 PM
Try removing auto increment option for user id
N replied to Venkat K on 25-Nov-10 09:46 PM
But i need the auto increment though..
Panji Tengkorak replied to N on 04-Jan-11 01:39 PM
Try this:

Create table users(user_id int not null auto_increment,name varchar(40) not null,admission_no varchar(8) not null,
password varchar(20) not null,email varchar(60) not null,Primary Key(user_id,email));

Does it work?

.
Panji Tengkorak replied to Panji Tengkorak on 04-Jan-11 01:41 PM
the above code works but you will have 2 primary key not sure if it's going to be a problem or not with your application but you have what you want: email as PK

.