在MySQL中创建索引时索引名称的意义是什么?

Wil*_*ill 20 mysql indexing

为了使用我做了类似的事情on duplicate key update:

CREATE UNIQUE INDEX blah on mytable(my_col_to_make_an_index);
Run Code Online (Sandbox Code Playgroud)

它工作得很好.我只是不确定索引名称的用途是什么 - 在这种情况下'blah'.我读过的东西说要用一个,但我无法理解为什么.它似乎没有在查询中使用,虽然我可以看到它导出架构.

那么......索引名称的用途是什么?如果它有助于最终的线条CREATE TABLE看起来像:

UNIQUE KEY `clothID` (`clothID`)
Run Code Online (Sandbox Code Playgroud)

Lan*_*ing 17

索引名称用于引用将来命令的索引.喜欢掉落指数.

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

只需考虑表名等索引名称.您可以轻松制作一个名为'blah'的表格.

CREATE TABLE blah (f1 int);
Run Code Online (Sandbox Code Playgroud)

但是''blah'对于将来的参考不是很有帮助.只是保持一致.就像是

CREATE UNIQUE INDEX field_uniq on mytable(field);
Run Code Online (Sandbox Code Playgroud)

要么

CREATE INDEX field1_field2_inx on mytable(field1, field2);
Run Code Online (Sandbox Code Playgroud)

  • 我可以在不同的表上创建相同名称的索引吗? (3认同)
  • @FrozenFlame 您可以在 MySQL 中使用,但不能在许多其他数据库中使用,例如 PostgreSQL。 (2认同)

ajr*_*eal 10

命名是允许全局命名空间,并帮助更好地理解表模式.

索引名称对于强制索引提示非常有用.尽量不要为索引和列使用相同的名称(模糊),并且对于像Windows这样的系统(不允许区分大小写),驼峰情况毫无意义.

例如,像这样:

unique key cloth_id_uniq (cloth_id); 
>>allow people knowing this an unique key on column cloth_id

fulltext key description_ft (description); 
>>allow people knowing this index is fulltext on column description
Run Code Online (Sandbox Code Playgroud)

我不认为有一个标准的命名约定,任何看似直观的东西都会有所帮助.