I've seen various articles which point to using a pattern of:
ID
(uniqueidentifier
) : PK, non-clusteredClusteredID
(int
) : INDEX, clustered (IDENTITY)- My other columns (various)
My interpretation of this pattern is that it allows a record to be identified using a uniqueidentifier
(which is useful in many situations), but means that the clustered index does not get so fragmented because of the incremental ordering of generated int identity
column values.
This all makes sense to me so far.
What I'm not fully understanding is that:
If the unique identifier is the uniqueidentifier
, then it makes sense for me to use this as the FK in related tables. Now, when executing a select statement joining the two tables SQL Server
will perform the join on the uniqueidentifiers
. However, seeing as it is actually the int index which is clustered, then I'd have thought that clustering on the int would not help performance with joins.
If my assumptions above are correct, then I'm not appreciating the benefit of adding the clustered int index.
I guess, therefore, that my assumptions are not correct. Could anybody tell me where I'm going wrong in my thinking?