What#39;s the difference between using INDEX vs KEY in MySQL?(在 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.这是为与其他数据库系统兼容而实施.
KEYis normally a synonym forINDEX. The key attributePRIMARY KEYcan also be specified as justKEYwhen given in a column definition. This was implemented for compatibility with other database systems.
这篇关于在 MySQL 中使用 INDEX 和 KEY 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MySQL 中使用 INDEX 和 KEY 有什么区别?
基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
