When I has do some SQL Tody, some confusion come up to me.
Its on the index && PRIMARY key && UNIQUE key in MySQL. So I Google it for the answers. There is a clearly answer on the
StackOverflow. So I share it in this BLOG.
About INDEX:
Firstly, we should understand KEY and INDEX is synonyms in MySQL. They mean the same thing.
The quersion: What is exactly the INDEX mean?
Here are a shortcut about the INDEX:
In databases your would use indexes to improve the speed of data retrieve. An index was typically created on columns used in
JOIN, WHERE, and ORDER by clauses.
There is a example about INDEX so you can understand it better:
Imagine You has a table called and you want to search for all the users which has the last users
name ' Smith '. Without an index, the database would has to go through all the records of the table:this are slow, because the more Recor DS you had in your database and the more work it had to does to find the result. On the other hand, an index would help the database skip quickly to the relevant pages where the ' Smith ' Records is held. This is very similar-to-we, humans, go through a phone book directory to find someone by the last name:we don ' t start Searching through the directory from cover to cover, as long we inserted the information in some order so we can use Skip quickly to the S ' pages.
About PRIMARY KEY:
Primary keys and unique keys are similar. A primary key is a column, or a combination of columns, which can uniquely identify a row.
About UNIQUE KEY:
When you specify a unique key to a column, no distinct rows in a table can has the same value.
INDEX && PRIMARY key && UNIQUE key