MySQL KEY关键字是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/924265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the KEY keyword mean?
提问by MartinodF
In this MySQL table definition:
在这个 MySQL 表定义中:
CREATE TABLE groups (
ug_main_grp_id smallint NOT NULL default '0',
ug_uid smallint default NULL,
ug_grp_id smallint default NULL,
KEY (ug_main_grp_id)
);
What does the KEY
keyword mean? It's not a primary key, it's not a foreign key, so is it just an index? If so, what is so special about this type of index created with KEY
?
什么是KEY
关键字是什么意思?它不是主键,也不是外键,那么它只是一个索引吗?如果是这样,这种类型的索引有KEY
什么特别之处?
回答by MartinodF
Quoting from http://dev.mysql.com/doc/refman/5.1/en/create-table.html
引自http://dev.mysql.com/doc/refman/5.1/en/create-table.html
{INDEX|KEY}
So KEY
is an INDEX
;)
所以KEY
是一个INDEX
;)
回答by sergtk
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.
KEY
通常是 的同义词INDEX
。key 属性PRIMARY KEY
也可以KEY
在列定义中指定时指定。这是为了与其他数据库系统兼容而实施的。
column_definition:
data_type [NOT NULL | NULL] [DEFAULT default_value]
[AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
...
Ref: http://dev.mysql.com/doc/refman/5.1/en/create-table.html
参考:http: //dev.mysql.com/doc/refman/5.1/en/create-table.html