tags:

views:

16

answers:

2

I have a query that gets all employee duties for a start date and end date against a database. Basically the table would be like

  • Emp
  • Duty
  • StartDate
  • EndDate

Should I give indexing for dates? what kind etc? to make things easier on db level (orm level for me it would be an attribute to set).There will be huge data depending on number of employees off course (expected) , better safe than sorry?

Please advice.

+1  A: 

A combined index on emp, startdate, enddate seems like a good choice. But it really depends on how you plan to access/query your data. A proper answer cannot really be given without knowning how your application works. Because in the end, the best solution is the solution that works for you.

Bor
would get all employee duties for a start date and end date mean index on startdate and end date alone or? mmmm
abmv
Generally I'd imagine your WHERE clause would look like this:`WHERE emp = X AND startDate .. AND endDate ..`
Bor
no emp get all emp duty so
abmv
get all emp duty for startdate and end date
abmv
+1  A: 

Assuming you have a primary key on this table, I would use non clustered indices on the date fields if you need to search them oftenly - this is more important the more data you have in the table.

Adding only two more indexes on the table shouldn't hurt (though I wouldn't index all fields - that is asking for trouble!).

Oded
you mean combine all emp + duty + std + end into one index right? hee??
abmv
I mean a different index for each field - shudder. But your's is even more cringe worthy ;)
Oded
Can you explain the repercussions on adding non clustered index on emp and duty separately ,since I use an orm and am fixing actually some orm code with attributes I see [Index()] on these I think leave them there maybe the orm on demand would throw some queries at them...? thanks again
abmv
@abmv - it depends on how you (the ORM) are going to query the DB - if emp and duty are used for your where clauses, having the indexing overhead may be a benefit. In general, the more indexes you have, the slower inserting will be - if you have lots of inserts you want to avoid excessive indexing.
Oded
ok thanks now I get it,my db knowledge was eroding away well.Not much inserts on employee duty table after it is set.I'm just analyzing the whole BL again.Thanks for your replies.
abmv