Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Which fields in the database can be set as primary keys?
Which fields in the database can be set as primary keys?
First understand what a primary key is: it uniquely identifies a row of data in a table.

1. Meaningless: Meaninglessness here is defined from the user's point of view. This nonsense will also reduce the information redundancy of the database to some extent. People usually refer to the primary key as an internal identifier. One of the reasons is "internal". The so-called internal, to some extent, refers to table records, to a large extent, databases. If you choose the information that is meaningful to users as the primary key when designing, you will face the user's demand for updating this information sooner or later, then you will violate its static nature.

2. Static: other meaning should not be considered in the primary key, except for uniquely identifying the association between the record and the foreign key. The ideal state is that it will not change after generation, so the primary key value should be considered not to be updated after generation. If the update operation is carried out, at least it shows that this information is meaningful to the user, then you violate the essence of meaninglessness. (Data integration may need to deal with primary keys, etc. This is done to ensure the integrity of the database-records are unique, which is not considered. )

Meaninglessness can often determine its static nature.

3. Short: Not only the number of fields composed of the primary key is small, but also the storage type of a single field in the primary key is short, so it is generally stereotyped; For the former, the main consideration is the factor of foreign key association; For the latter, performance is the main consideration. The simplicity of primary key is very helpful to the convenience of table association and the performance of retrieval.

For detailed reference:/article/30907.htm.