[thelist] mysql - unique index combos

Hassan Schroeder hassan at webtuitive.com
Tue Feb 22 18:10:21 CST 2005


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.

> +-------------+-----------------+
> | ProjectID   | DocumentID      |
> +-------------+-----------------+
> | 327         | 440             |
> +-------------+-----------------+
> 
> 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?  

   ALTER TABLE whatever ADD PRIMARY KEY (ProjectID, DocumentID)

should do it :-)

HTH,
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.




More information about the thelist mailing list