1 Use autogrow fields as primary keys ( General multi-purpose int type definition ), Also known as a non business primary key ( Logical or proxy primary keys ) This means that this column of data has nothing to do with business , Designed as primary key only .
    advantage : Self growing fields are often used integer bigint type , Most 8 Bytes . Index and foreign key The amount of space occupied is reduced , Add, delete, modify and search
efficient . Business change , No effect , There is no need to update the primary key .
    shortcoming : Unable to transfer database , For example, a batch of data in the table transfer or Attached to
In another table , Since it is a self growing field , That would make it impossible to transfer , Because some data may already exist in another table , Will cause primary key conflict . Defects of self growing fields . Integrity of business data , There is no guarantee .
2. Use business fields as primary keys .
advantage : The database can be transferred , Maximize space savings , Because there is no additional non business field as the primary key . It can ensure the integrity of business logic . Avoid spam , Banks use business fields as primary keys , Although inefficient , But it's safe .
shortcoming : If business changes , It may be necessary to modify the primary key , give an example : country A The table uses the ID number as the primary key , Then the ID number column in many other tables comes from the ID card table A Primary key in ( Foreign key ), So if the ID number is upgraded , For example, from 1 Upgrade to 2 generation , Then the foreign key of the associated table
Index of Everything has to change , Extremely inefficient Because it will update a list of tables using the foreign key , You can see that if you use the business field as the primary key , Make sure that the primary key does not change frequently .
    summary : What is the primary key , It also depends on business needs , physical truth , There is no fixed standard .

©2019-2020 Toolsou All rights reserved,
Huawei Mate 40 Pro+ 5G exposure : Leica film lens , Ceramic body ( Essence 2020 year 6 month 3 Daily update ) TypeScript Detailed explanation of Chinese interface Online troubleshooting HTTP Status code ——415 and 406 use PyMC3 Bayesian statistical analysis was performed ( code + example )golang One line of code converts the slice into a semicolon separated string Result Encapsulation of return result information The project followed for a year , The customer finally said no Three.js - OrbitControls Orbit control around target target parameter Java Thread of Sleep() Summary of usage Vue Get the text and option value of the drop-down box