Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unique key on date range columns (temporal validity)

John_KMar 27 2017

A lot of systems use date-tracking functionality, where a record is valid from one date to another.

ID  Date_From    Date_To

1   01-Jan-2017  12-Jan-2017

1   13-Jan-2017  31-Jan-2017

in most instances we would not want overlapping date ranges for a given ID. We can put in a unique key on say (ID, Date_From) which would eliminate duplicates, or we could write some kind of trigger to detect duplicates (with all kinds of workarounds for mutating table etc). However I think it would be really useful if we could have a special constraint (or option to the "Add Period" clause when enabling Temporal Validity such as "No Overlap(key columns)") whereby for a given set of columns, they cannot intersect with another record having those columns. I.e. the following would not be allowed.

ID  Date_From  Date_To

1   01-Jan-2017 12-Jan-2017

1   03-Jan-2017 31-Jan-2017

I appreciate on 11g and earlier it might have been impractical to implement however with TV now being a feature of the database rather than just being implemented as two date columns on a record, I'm sure there must be some underlying structures which would make this reasonably efficient to build into the database that wouldn't have the overhead of having to scan loads of records looking for intersections.

Comments
Post Details
Added on Mar 27 2017
7 comments
1,676 views