sql - what should i index -


i'm complete index dummie, i've read , watched quite bit of vids on indexing can't seem figure out.

the table looks following:

id          int componentid int value       float timestamp   datetime 

imagine database having 2 million records , following:

select value log  componentid = x  , timestamp >= select convert(varchar(8),dateadd(day, -1, getdate()),112) 

that should me values selected component within last 24 hours

and im wondering if should index on componentid, timestamp or both

thanks in advance!

i suggest create covering index on table like:

create unique nonclustered index idx_indexname on dbo.tablename(componentid, timestamp)  include(value) 

this should improve performance of query index seek. value stored in leafs of index rid of lookups data selecting in index.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -