Jump to content


Photo

Multiple UNIQUE KEY columns in same table???


  • Please log in to reply
2 replies to this topic

#1 freak4php

freak4php
  • Members
  • Pip
  • Newbie
  • 2 posts
  • LocationUSA

Posted 05 May 2003 - 03:02 AM

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

Thank you very much
-freak4php

#2 barbatruc

barbatruc
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationMontreal, Quebec, Canada

Posted 05 May 2003 - 04:41 PM

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.
Unfortunately, PHP \'empowered every moron with a copy of Windows notepad to be \"web programmers\". (...) Give PHP a real INFRASTRUCTURE. Use PEAR!!!\'

#3 freak4php

freak4php
  • Members
  • Pip
  • Newbie
  • 2 posts
  • LocationUSA

Posted 05 May 2003 - 10:50 PM

Thank you VERY much!!!
-freak4php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users