tags:

views:

304

answers:

1

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), 
....

However I found a code using KEY instead of INDEX as following.

...
KEY order_date (order_date) 
...

I am not able to find any document in MySQL official page.

Could anyone tell me what the differences are between KEY and INDEX? What I can see the difference is that when I uses KEY ..., I need to repeat the word, e.g. KEY order_date (order_date).

+1  A: 

There's no difference. They are synonyms.

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.

nos