I am storing intervals where From < To for each entry. If I build an index on "From", then I can get the minimum and maximum entries efficiently when inserting a new record to do a validation check. However, this doesn't help if there were a big gap somewhere in these entries where a given record could've easily fit. For example:
[3, 5]
[8, 9]
If I want to insert [6,7] or [1,2] above, what is the best way to check?
Just wondering if there's an efficient way of ensuring that a record doesn't overlap with any of the existing entries without comparing against all of them.
EDIT: I am looking for a c#.Net solution. Sql server is just being used as a data store. I thought it important to mention since querying to check existing values is a part of it.