Click to See Complete Forum and Search --> : Help with MySQL and index creation


Doctor Luz
November 16th, 2007, 04:37 AM
I have a MySQL Database with a table called "DATA" and I want to add an index to a field called "NAME" which has duplicate entries, because some people in the DB has the same name.

I am trying to do it with MySQLAdmin but I can't because when I try to add the index there is an error message saying that "the index can't be created because there are duplicate entries in the field DATA"

Is impossible to create in MySQL an index if there are duplicate entries?

Thank you.

Doctor Luz
November 16th, 2007, 04:58 AM
Forget it sorry

I had the combo box in Primary key and not in index.

:blush:

Solved

davide++
November 16th, 2007, 05:12 AM
Hi all.

What you're trying to do is to create a primary key rather than an index; a primary key is a constraint that prevents the insertion of duplicated data into a column, whereas an index is a database object that help to grow the speed of queries. You can define a "unique index", so you add the constraint that values into field must be distinct, and in this case the index acts like a primary key (usually this kind of indexes are called alternative key).
In any case, if you want create an unique index or a primary key on a column you have to be sure that the column holds yet distinct values before the creation: if no, you have to delete the duplicated values.