Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

indexing - What is the significance of the index name when creating an index in MySQL?

I've done something like this in order to use on duplicate key update:

CREATE UNIQUE INDEX blah on mytable(my_col_to_make_an_index);

and its worked just fine. I'm just not sure what the purpose of the index name is -- in this case 'blah'. The stuff I've read says to use one but I can't fathom why. It doesn't seem to be used in queries, although I can see it if I export the schema.

So ... what purpose does the index name serve? If it helps the line in the CREATE TABLE ends up looking like:

UNIQUE KEY `clothID` (`clothID`)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The index name is used to reference the index for future commands. Like drop index.

http://dev.mysql.com/doc/refman/5.0/en/drop-index.html

Just think of index names like table names. You can just as easily make a table called 'blah'.

CREATE TABLE blah (f1 int);

But 'blah' isn't very helpful for future reference. Just be consistent. something like

CREATE UNIQUE INDEX field_uniq on mytable(field);

or

CREATE INDEX field1_field2_inx on mytable(field1, field2);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...