INDEX && PRIMARY key && UNIQUE key

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.