问题描述
如果表中的 ID 列是唯一标识符 (Guid),那么在 ID 列上创建聚集主键是否有意义?
If your ID column on a table is a unique identifier (Guid), is there any point creating a clustered primary key on the ID column?
鉴于它们是全局唯一的,排序将如何进行?
Given that they are globally unique, how would the sorting work?
推荐答案
GUID 因为它们实际上是随机值(这会破坏"聚集索引),所以它们对于性能来说很糟糕,而且它们对于索引来说很糟糕,因为条目较少适合单个页面/范围(SQL Server 术语).SQL Server 2005 引入了 newsequentialid()
这有助于解决第一个问题.
GUIDs as they are are terrible for performance since they are effectively random values (this "breaks" clustered index), and they are awful for indexes, since less entries fit on a single page/extent (SQL Server terms). SQL Server 2005 introduces newsequentialid()
which helps solving first problem.
这篇关于SQL Server 中唯一标识符 ID 列上的聚集主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!