What data type is recommended for ID columns?

后端 未结 9 1794
既然无缘
既然无缘 2021-02-08 04:35

I realize this question is very likely to have been asked before, but I\'ve searched around a little among questions on StackOverflow, and I didn\'t really find an answer to

9条回答
  •  故里飘歌
    2021-02-08 05:20

    If you use a long, you could create over 1000 a second and not run out of primary keys for 29 million years.

    Others have already mentioned some of the advantages of using an integer type instead of a UUID/GUID. One of the big advantages is the speed and compactness of the indexes.

    An application I was recently involved in where I did the database design, I needed UUIDs, but didn't want to give up the advantages of using longs for primary keys, so I had a "allIds" table that mapped every primary key in the system to a UUID. All my primary keys were generated from a single sequence, so they were all unique across all tables.

提交回复
热议问题