freak4php Posted May 5, 2003 Share Posted May 5, 2003 Can I have more than one \'UNIQUE KEY\' column designation in the same MySQL table? Thank you very much Quote Link to comment Share on other sites More sharing options...
barbatruc Posted May 5, 2003 Share Posted May 5, 2003 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). JP. Quote Link to comment Share on other sites More sharing options...
freak4php Posted May 5, 2003 Author Share Posted May 5, 2003 Thank you VERY much!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.