What does the KEY keyword mean?

MysqlIndexing

Mysql Problem Overview


In this MySQL table definition:

CREATE TABLE groups (
  ug_main_grp_id smallint NOT NULL default '0',
  ug_uid smallint  default NULL,
  ug_grp_id smallint  default NULL,
  KEY (ug_main_grp_id)
);

What does the KEY keyword mean? It's not a primary key, it's not a foreign key, so is it just an index? If so, what is so special about this type of index created with KEY?

Mysql Solutions


Solution 1 - Mysql

Quoting from create-table - indexes andkeys

{INDEX|KEY}

So KEY is usually an INDEX

> KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can > also be specified as just KEY when given in a column definition. This > was implemented for compatibility with other database systems.

Solution 2 - Mysql

KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.

column_definition:
      data_type [NOT NULL | NULL] [DEFAULT default_value]
      [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
      ...

Ref: http://dev.mysql.com/doc/refman/5.1/en/create-table.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStanView Question on Stackoverflow
Solution 1 - MysqlMartinodFView Answer on Stackoverflow
Solution 2 - MysqlsergtkView Answer on Stackoverflow