Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

indexing

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`) 
like image 723
Will Avatar asked Jan 05 '11 05:01

Will


People also ask

What is the importance of MySQL index?

Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs.

What is indexing and how do you create an index in MySQL?

A database index is a data structure that improves the speed of operations in a table. Indexes can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records.

What is the purpose of an index defined on a given attribute of a table in the database?

Indexes are used to quickly locate data without having to search every row in a database table every time a database table is accessed. Indexes can be created using one or more columns of a database table, providing the basis for both rapid random lookups and efficient access of ordered records.


1 Answers

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); 
like image 183
Lance Rushing Avatar answered Sep 28 '22 15:09

Lance Rushing