Using GUIDs in Primary Keys / Clusted Indexes

后端 未结 4 1248
孤独总比滥情好
孤独总比滥情好 2021-01-05 02:57

I\'m fairly well versed in SQL server performace but I constanly have to argue down the idea that GUIDs should be used as the default type for Clusterd Primary Keys.

<
4条回答
  •  离开以前
    2021-01-05 03:26

    Drawbacks of using GUID as primary key:

    • No meaningful ordering, means indexing doesn't give performance boost as it does with an integer.
    • Size of a GUID 16 bytes, versus 2, 4 or 8 bytes for an integer.
    • Very difficult for humans to remember, so no good as a reference id.

    Advantages:

    • Allow non-guessable primary keys that can therefore be less dangerous when displayed in a web page query string or in the application.
    • Useful in Databases that don't provide an auto increment or identity data type.
    • Useful when you need to join data between two disparate data sources across platforms or environments.

    I thought the decision as to whether to use GUIDs was pretty simple, but maybe I'm unaware of other issues.

提交回复
热议问题