Take the 2-minute tour ×

I have table broker with this form

broker_code char(10) primary key




and i have add to it another primary key with this form

code int nut null auto_increment

and wrote this query


but it this error.

multiply primary key defined.

what can i do?

share|improve this question
Why do you need another PRIMARY key and AUTO_INCREMENT? What exactly the requirement is? Consider to explain. –  Framework Mar 18 '11 at 12:31
And what do you need another PK for? Can't you go with an index key, possibly with two columns? –  mingos Mar 18 '11 at 12:34
add comment

3 Answers

up vote 3 down vote accepted

You can't have two primary keys... However, you can have a "candidate" key or Unique that also prevents duplication on other criteria... Such as a person in a human resources application. You can have an internal "employee ID" which is the primary, but also a candidate key on a person's Social Security Number which SHOULD never be duplicated... and if so, it would through up a red-flag to H/R to verify who a person is.

share|improve this answer
add comment

This code below has a composite primary key with alter table.

ALTER TABLE ex_table
ADD PRIMARY KEY (`name`,`id`)
share|improve this answer
add comment

I'm not sure because I can't see the structure of your current table 'broker'. But my guess is that you already defined another Primary Key.

You are only allowed to have 1 primary key per table.

share|improve this answer
add comment

Your Answer


