What's the difference between using INDEX vs KEY in MySQL?
There's no difference. They are synonyms.
From the CREATE TABLE
manual entry:
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.
Here is a nice description about the "difference":
"MySQL requires every Key also be indexed, that's an implementation detail specific to MySQL to improve performance."
It is mentioned as a synonym for INDEX
in the 'create table' docs:
MySQL 5.5 Reference Manual :: 13 SQL Statement Syntax :: 13.1 Data Definition Statements :: 13.1.17 CREATE TABLE Syntax
Nos already cited the section and linked the help for 5.1.
Like PRIMARY KEY
creates a primary key and an index for you,
KEY
creates an index only.