PDA

View Full Version : MySQL indexes error


rsp12uk
01-02-2004, 04:36 PM
Hi everyone,

I have a table where I need to set up three columns that can't duplicate. But, the thing is this. If col1 is duplicated and col2 and col3 have another values, then the entry can exists. Only if col1, col2 and col3 duplicate then the record is not allowed.

Sorry for the mass, I really tried to make it understandable.

Thanks a lot everyone!

raf
01-03-2004, 01:47 AM
You need to create a multi-field index

Like this:

ALTER TABLE yourtablename ADD UNIQUE yourindexname (col1,col2,col3);

The UNIQUE means hat duplicate values for the combination col1-col2-col3 are not allowed.

rsp12uk
01-03-2004, 09:32 PM
Thanks a lot buddy.

I knew that it is something like that, I was aministering seven big databases for around 2.5 years and I forgot how to do multi-fielded index, shame. However, thank you a whole big great lot.

Thanks!

raf
01-03-2004, 09:59 PM
Your welcome. I've been there...
(Like the french say : "L'alcole et Flavie")