Primary Key and unique Index Analysis

Source: Internet
Author: User


In fact, the index of a specified column is equivalent to sorting the specified column. Why? Because sorting is conducive to querying this column, it can greatly increase the query efficiency. (Some people may think that sorting all columns can increase the query efficiency of the entire database? This idea is wrong because index creation also consumes system resources. Creating an index for each column in each table will cause a great burden on the system, let alone efficiency !) --------- Simply put, creating a column index is equivalent to creating a column sort.
The primary key is actually an index, but this index is different from the general index. The difference is that every record in the column where the primary key is located is unique, it can also be said that the same record cannot appear in the primary key, and only one primary key can exist in the same table. (The primary key is equal to the index, and the index is not necessarily equal to the primary key) ---------- simply put, the primary key is a special index where the same record cannot appear in the column, and this index can only appear once in the table. Www.2cto.com 1. the primary key must be a unique index, and the unique index is not necessarily a primary key; 2. A table can have multiple unique indexes, but only one primary key. 3. the primary key column does not allow null values, while the unique index column does. The primary key has a unique identifier in the table. It cannot be repeated and cannot be blank. When a foreign key is set up in other tables to associate the current table, only the primary key can be associated. Unique index. Specifically, it is a unique constraint. create unique index index_id on (id) is a field used to restrict the unique constraints created when the current table is inserted. One is used as a unique identifier, and the other is used as a unique identifier.
From column simonjay2007

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.