Index v.s.之间有什么区别关键MySQL [英] What are differences between Index v.s. Key in MySQL

查看:142
本文介绍了Index v.s.之间有什么区别关键MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用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官方页面找到任何文件。

I am not able to find any document in MySQL official page.

有人能告诉我KEY和INDEX之间有什么区别吗?
我能看到的不同之处在于,当我使用KEY ...时,我需要重复这个词,例如KEY order_date(order_date)。

Could anyone tell me what the differences are between KEY and INDEX? What I can see the difference is that when I uses 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.

这篇关于Index v.s.之间有什么区别关键MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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