Jump to content


This topic is now archived and is closed to further replies.


Multiple UNIQUE KEY columns in same table???

Recommended Posts

Can I have more than one \'UNIQUE KEY\' column designation in the same MySQL table?


Thank you very much

Share this post

Link to post
Share on other sites

Yes you can.


Several fields can be part of the same Unique key. They\'ll be combined together to ensure they are unique. So let\'s say you have First Name, Last name. You could say full name won\'t appear twice by setting a Unique key as a combination of First Name and Last Name. So there might be several people with first name John in your database and several people with last name Doe, but only one John Doe.


You can also have several Unique keys and use them as a combination of one or several fields. With the First name / Last name example, you would have 2 unique keys, one for each fields and this way you could only have one person with first name John and only one person with last name Doe (this doesn\'t make sense naturally...).


Primary key acts like UNIQUE key, only you cannot have more than one PRIMARY KEY in each table. I\'m not sure but it doesn\'t seem that you can have several fields for a Primary key (I can\'t confirm that now - but it makes sense that a Primary key should only have one field - foreign tables are then logically using primary keys for relations between them).



Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.