In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces what is the design principle of MySQL primary key. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
The relational database depends on the primary key-it is the cornerstone of the database physical schema. The primary key has only two uses at the physical level:
1. Uniquely identifies a row.
two。 As an object that can be effectively referenced by a foreign key.
Based on these two uses, here are some of the principles I follow when designing primary keys at the physical level:
1. The MySQL primary key should be meaningless to the user. If the user sees the data in a join table that represents a many-to-many relationship and complains that it is useless, it proves that its primary key is well designed.
2. The MySQL primary key should be in a single column to improve the efficiency of join and filter operations.
Note: people who use compound bonds usually have two reasons to excuse themselves, both of which are wrong. One is that the primary key should have practical significance, however, making the primary key meaningful is only convenient for artificially destroying the data base. The second is that by using this method, two foreign keys can be used as primary keys in join tables describing many-to-many relationships. I also object to this approach, because compound primary keys often lead to bad foreign keys, that is, when a joined table becomes the master of another slave table and becomes part of the primary key of this table according to the second method above, however, this table may again become the master table of other slave tables. Its primary key may become part of other slave table primary keys, so that the lower the slave table, the more columns its primary key will contain.
3. Never update the MySQL primary key. In fact, because the primary key has no other use than uniquely identifying a row, there is no reason to update it. If the primary key needs to be updated, the principle that the primary key should be meaningless to the user is violated.
Note: this principle does not apply to data that often requires data consolidation during data conversion or multi-database consolidation.
4. The MySQL primary key should not contain dynamically changing data, such as timestamp, creation time column, modification time column, etc.
5. The MySQL primary key should be automatically generated by the computer. If a person interferes with the creation of a primary key, it will have a meaning other than a unique identification line. Once this limit is crossed, there may be an incentive to modify the primary key, so that the key means used by the system to link and manage record rows will fall into the hands of people who do not understand the database design.
These are all the contents of the article "what are the design principles of MySQL primary keys?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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: 232
*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.