Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 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 Reply

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...