Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating tables with multiple primary keys

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I tried to create tables with more than one primary keys, but I got the "multiple primary keys devined" error messages. Could anyone tell me how to do that in MySQL? Thanks!
 
Its in the principle of relation databases that there can be just one primary key. But on the other hand, a primary key is just another unique index.

So, if you like to have two "primary keys" on a table you create one primary key and a unique key.

create table xxx (
id1 int not null,
id2 int not null,
...
primary key (id1));

create unique index xxx_ix on xxx(id2);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top