What are the reasons *not* to use a GUID for a primary key?

后端 未结 8 1818
梦谈多话
梦谈多话 2020-12-24 02:24

Whenever I design a database I automatically start with an auto-generating GUID primary key for each of my tables (excepting look-up tables)

I know I\'ll never lose

8条回答
  •  误落风尘
    2020-12-24 03:07

    Adding to ewwwn:

    Pros

    • It makes it nearly impossible for developers to "accidentally" expose the surrogate key to users (unlike integers where it happens almost all the time).
    • Makes merging databases several orders of magnitude simpler than dealing with identity columns.

    Cons

    • Fatter. The real problem with it being fatter is that it eats up more space per page and more space in your indexes making them slower. The additional storage space of Guids is frankly irrelevant in today's world.
    • You absolutely must be careful about how new values are created. Truly random values do not index well. You are compelled to use a COMB guid or some variant that adds a sequential element to the guid.

提交回复
热议问题