0

I have two datetimeoffset fields in table (sql azure), Migrated and Updated

I usually do this search select * from table where Migrated < Updated

What would be the right strategy for indexing these fields?

  1. two indexes, one for each field
  2. one index on Migrated, Updated
  3. one index on Updated, Migrated

Table is huge and requires indexing...

Cherven
  • 1,101
  • 3
  • 17
  • 26

1 Answers1

2

In most versions of SQL Server, you can take the following approach. I have not tried this in SQL Azure.

Create a computed column and then an index on that:

alter table t add MigratedToUpdatedTime as (datediff(seconds, Migrated, Updated))

create index t_MigratedToUpdatedTime on t(MigratedToUpdatedTime);

Then in your where clause, you can do:

where MigratedToUpdatedTime > 0;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • That helps. !!! I also used these posts http://stackoverflow.com/questions/15585330/calculated-column-in-ef-code-first and http://stackoverflow.com/questions/15585330/calculated-column-in-ef-code-first to implement idea proposed by Gordon – Cherven Apr 10 '15 at 19:04