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 有什么区别?
基础教程推荐
- oracle区分大小写的原因? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在多列上分布任意行 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
