在 MySQL 中使用 INDEX 和 KEY 有什么区别? [英] What's the difference between using INDEX vs KEY in MySQL?

查看:48
本文介绍了在 MySQL 中使用 INDEX 和 KEY 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在以下代码中使用 INDEX.我知道如何使用外键主键.

I know how to use INDEX as in the following code. And I know how to use foreign key and primary key.

CREATE TABLE tasks ( 
  task_id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
  parent_id INT UNSIGNED NOT NULL DEFAULT 0, 
  task VARCHAR(100) NOT NULL, 
  date_added TIMESTAMP NOT NULL, 
  date_completed TIMESTAMP, 
  PRIMARY KEY (task_id), 
  INDEX parent (parent_id), 
  ....


但是我发现了一个使用 KEY 而不是 INDEX 的代码,如下所示.


However I found a code using KEY instead of INDEX as following.

...
KEY order_date (order_date) 
...


我在 MySQL 官方页面上找不到任何解释.谁能告诉我 KEY 和 INDEX 之间有什么区别?


I could not find any explanation on the official MySQL page. Could anyone tell me what is the differences between KEY and INDEX?

我看到的唯一区别是当我使用KEY ...时,我需要重复这个词,例如
KEY order_date(order_date).

The only difference I see is that when I use KEY ..., I need to repeat the word, e.g.
KEY order_date (order_date).

推荐答案

没有区别.它们是同义词.

There's no difference. They are synonyms.

来自 CREATE TABLE 手动输入:

From the CREATE TABLE manual entry:

KEY 通常是 INDEX 的同义词.键属性 PRIMARY KEY 可以在列定义中给出时,也可以仅指定为 KEY.这是为与其他数据库系统兼容而实施.

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.

这篇关于在 MySQL 中使用 INDEX 和 KEY 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆