To ensure uniqueness there is a composite PK (clustered) containing:
[timestamp] [datetime2]
[userId] [varchar](36)
[cost_type] [varchar](20)
There are two more columns in the table:
[cost_cent] [bigint] NULL
[consumption_cent] [bigint] NULL
Composite clustered primary keys are not ideal (incl. varchar) but what is the alternative?
Having a heap table with a non clustered primary key? Additionally add another clustered index? But on what column? There is no identity column.
Background: there is a constant insert/update on this table via Merge
statements. Table size is ~50 million rows
Queries will use the PK with a time range mainly.