Index v.s.之间有什么区别关键MySQL [英] What are differences between Index v.s. Key in 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.
From the CREATE TABLE
manual entry:
KEY
通常是INDEX
的同义词。在列定义中给出时,键值属性PRIMARY KEY
也可以将
指定为KEY
。这是为了与其他数据库系统兼容而实现的
。
KEY
is normally a synonym forINDEX
. The key attributePRIMARY KEY
can also be specified as justKEY
when given in a column definition. This was implemented for compatibility with other database systems.
这篇关于Index v.s.之间有什么区别关键MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!