A co-worker created a table similar to this:
EmpID
ShiftStartDateTime
ShiftEndDateTime
PayRate
AnotherColumn
AnotherColumn
The primary key includes all columns (not sure why, I need to discuss with him).
The queries will primarily involve filtering against the EmpID and StartDateTime columns.
Assumming all columns need to part of the primary key, should seperate index(es) be added on the EmpID and StartDateTime columns?
First of all, having all fields in primary key looks very suspicious to me. If it’s also a clustered index, you will have a great overhead while inserting/updating records. Normally, you never update value of primary key. As to your question, that depends on the order of columns in you PK. If it’s
EmpID, ShiftStartDateTime,ShiftEndDateTime,PayRate,AnotherColumn, AnotherColumnand you queries will filter byEmpID and StartDateTime, then this index will be used, and you don’t need extra (which will be a huge waste of space)