In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you mysql has a primary key also need to create an index, I hope you will learn a lot after reading this article, let's discuss it together!
Mysql primary key does not need to build an index, the primary key has the function of index; when creating or setting the primary key, mysql will automatically add a unique index corresponding to the primary key, without the need for additional addition. The database management system automatically generates a unique index for the primary key, so the primary key is a special index.
When you create or set a primary key, mysql automatically adds a unique index corresponding to the primary key, without the need for additional additions.
If the primary key is not used in the query conditions, you can set your query field to the index. If you want to set an index on the primary key, the primary key has an index function.
For example, if you create a table in mysql in the following figure, you can see that only the primary key PRIMARY KEY is set in the CREATE TABLE statement, and there is no statement to build the index, but the index information shows the unique primary key index, which is created by mysql itself.
The difference and relation between database primary key and index
1. The primary key must be a unique index, but the unique index is not necessarily a primary key.
A primary key is an attribute or attribute group that uniquely identifies a row in a table. A table can only have one primary key, but it can have multiple candidate indexes. Because the primary key can uniquely identify a row of records, you can ensure that there are no errors when performing data updates and deletions. Primary keys also often form referential integrity constraints with foreign keys to prevent data inconsistencies. The database management system automatically generates a unique index for the primary key, so the primary key is also a special index.
2. Unique index identifies that the index value is unique. A table can have multiple unique indexes, but only one primary key.
3. The primary key column cannot be empty, but the unique index column can be empty.
4. A table can have only one primary key, but it can have multiple indexes.
Popular example: the primary key is equivalent to the page number of a book, and the index is equivalent to the book's catalogue.
After reading this article, I believe you still need to create an index if you have a primary key to mysql. I want to know more about it. Welcome to follow the industry information channel. Thank you for your reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.