Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "ADD KEY" and "ADD INDEX" in MySQL? [duplicate]

I dump database and i have one question. What does this query?

ALTER TABLE `ps_cart_rule` ADD KEY `id_customer` (`id_customer`,`active`,`date_to`); ALTER TABLE `ps_cart_rule` ADD KEY `id_customer_2` (`id_customer`,`active`,`highlight`,`date_to`); 

What is diffrence between ADD KEY and ADD INDEX?

like image 996
Bejkrools Avatar asked Sep 04 '15 07:09

Bejkrools


People also ask

What is the difference between key and index in MySQL?

There's no difference. They are synonyms. From the CREATE TABLE manual entry: KEY is normally a synonym for INDEX .

What does add key do in MySQL?

As per MySql documentation, 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. In your case ADD KEY will explicitly define index on that field.

How many types of indexes are there in MySQL?

MySQL has three types of indexes: INDEX, UNIQUE (which requires each row to have a unique value), and PRIMARY KEY (which is just a particular UNIQUE index).

What is multiple key in MySQL?

A composite key in MySQL is a combination of two or more than two columns in a table that allows us to identify each row of the table uniquely. It is a type of candidate key which is formed by more than one column.


1 Answers

KEY is a synonym for INDEX.

... | ADD {INDEX|KEY} [index_name] ...

Check the MySQL documentation for ALTER TABLE.

like image 79
Kristian Vitozev Avatar answered Oct 02 '22 16:10

Kristian Vitozev