Using GUIDs in Primary Keys / Clusted Indexes

后端 未结 4 1290
孤独总比滥情好
孤独总比滥情好 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:24

    Using a guid (unless it is a sequential GUID) as a clustered index is going to kill insert performance. Since the physical table layout is aligned according to the clustered index, using a guid which has a random sequencing order will cause serious table fragmentation. If you want to use a guid as a PK/Clustered index it must be a sequential guid using the newsequentialid() function in sql server. This will guarantee that the generated guids are ordered sequentially and prevent fragmentation.

提交回复
热议问题