There are a few things to consider here:
- How is data most often looked up in this table?
- How is data most often sorted in this table?
- Does this table relate to others as the parent record (i.e. will other tables FK to the PK of this table)?
Also, please keep in mind:
- The key fields of a Clustered Index are copied into the non-clustered indexes on the same table
- For Clustered Indexes that are not a Primary Key (implied unique) or at least declared as
UNIQUE
, a hidden "uniqueifier" field is added to rows that would otherwise be duplicates. NEWSEQUENTIALID()
is sequential per each restart of the SQL Server service. It is possible that the starting value after a restart is less than the previous lowest value.
Hence:
- If the PK field of this table shows up as a FK field in other tables, there is a definite performance implication of choosing to use a
UNIQUEIDENTIFIER
instead of anINT
as the FKed tables would then have a larger FK field in them. - How many rows do you really expect to have in this table? INT is 4 bytes (compared to the 8 bytes of a BIGINT) and has a max value of 2,147,483,647. If you might have slightly over 2.14 billion items, you can also start the IDENTITY range at the min value of each datatype, which for INT is -2,147,483,648. Starting at the low-end gives you the full 4.294 billion values to use. Compared to the 8 bytes of the DATETIME field if going with the
Created
field, plus add in the size of another field to make it unique, or the uniqueifier for any duplicate rows. - Since the key field(s) of the Clustered Index are included in Nonclustered indexes, that increases the chances of having a covering index without needing to
INCLUDE
other columns. Meaning, if you have the Clustered Index on the INT PK and a Nonclustered index on the UNIQUEIDENTIFIER, then JOINing to another table on that INT PK field while specifying the GUID value in a WHERE clause (assuming no other fields from this table are in the query) won't have to go back to the table since the Nonclustered Index will have both of the requiered fields in it. Does theCreated
field give the same benefit? Likely not.
IF no other tables ever JOIN to this table:
- THEN it might be ok to use the
Created
field as the non-unique Clustered Index and theId
field as the Nonclustered PK. - ELSE it is typically best to add an INT (unless you need more than 4.294 billion values) IDENTITY field,
AssetId
, as the Clustered PK, and theId
UNIQUEIDENTIFIER field as a Nonclustered Index. Since you likely already have code referencing the UNIQUEIDENTIFIER field asId
, I wouldn't change that name.