Problem Description
I know how to use INDEX as in the following code. And I know how to use *foreign key* and *primary key*.
```mysql
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 NULL,
PRIMARY KEY ( task_id ),
INDEX parent ( parent_id )
)
```
However I found a code using `KEY` instead of `INDEX` as following.
```mysql
CREATE TABLE orders (
order_id int unsigned NOT NULL AUTO_INCREMENT,
-- etc
KEY order_date ( order_date )
)
```
I could not find any explanation on the official MySQL page. Could anyone tell me what is the differences between `KEY` and `INDEX`?
The only difference I see is that when I use `KEY ...`, I need to repeat the word, e.g. `KEY order_date ( order_date )`.
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?