how to create two primary key with alter table
I have table broker wi开发者_运维技巧th this form
broker
{
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
ALTER TABLE broker ADD code INT NOT NULL AUTO_INCREMENT,
ADD PRIMARY KEY (code);
but it this error.
multiply primary key defined.
what can i do?
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.
This code below has a composite primary key with alter table.
ALTER TABLE ex_table
ADD PRIMARY KEY (`name`,`id`)
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.
精彩评论