[thelist] mysql - unique index combos

Mattias Thorslund mattias at inreach.com
Tue Feb 22 18:19:01 CST 2005


No problem at all.

Simply make those two fields into the Primary Key. If your table already 
has a different PK and you can't change that, you can also create a 
unique key that includes both fields.

MySQL has a good manual online, which will tell you how: 
http://dev.mysql.com/doc/

/Mattias



David Siedband wrote:

> I have some index tables in mysql (v4.x) that have two fields, each 
> being a unique ID from another table.  What I'd like to do is allow a 
> combination of keys to be entered only once.
>
> for example:
>
> +-------------+-----------------+
> | ProjectID  | DocumentID |
> +-------------+-----------------+
> | 327           | 440              |
> | 446           | 743              |
> | 226           | 444              |
> | 446           | 743              |
> | 226           | 444              |
> +-------------+-----------------+
>
> Is there a way to declare a unique index on these two fields, such 
> that when someone tries to enter a combination that is already in the 
> table it doesn't enter a duplicate entry?  ...or do I need to put this 
> logic in my application instead?
>
> thx
> -- 
> David Siedband
> generation-xml.com
>



More information about the thelist mailing list