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,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Some East 14 Pay change 16 salary , Sincerity or routine ? Browser kernel ( understand )java Four functional interfaces ( a key , simple )HashMap Explain in detail html Writing about cherry trees , Writing about cherry trees os Simple use of module