Jump to content

Multiple UNIQUE KEY columns in same table???


freak4php

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.