您的位置:首页 > 数据库 > MySQL

Mysql中创建索引的INDEX和KEY

2016-04-21 00:00 411 查看
摘要: 结论:index和key没有区别(即使有区别,也可以忽略)

一、问题

被问到,mysql为什么用key创建索引,而不是index。这个被难住了。

二、查一下

w3school的sql文档

关于key和index只有三个页面,primary key,foreign key和create index。

看来使用index是比较标准的语法。

stack overflow的帖子

mysql的官方文档

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.

这篇对话文章,也挺有意思:

http://discuss.fogcreek.com/joelonsoftware5/default.asp?cmd=show&ixPost=152398

In MySQL, KEY is equivalent to INDEX. It won't check for duplicates without UNIQUE in front of it.

Egor
Wednesday, June 16, 2004

Boy, they should really change the name or behavior then, because that's a *big* departure from the relational definition of "KEY".

Captain McFly
Wednesday, June 16, 2004

另外,我们使用index和key分别创建索引,导出的create syntax是一样的。

三、结论

结论:index和key没有区别(即使有区别,也可以忽略)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql key index