I have quite a few situations where I have database structures similar to:
TABLE Event (EventID INT PrimaryKey, Start DATETIME, Finish DATETIME); and
TABLE EventTask (EventTaskID INT PrimaryKey, EventID INT ForeignKey, TaskStart DATETIME, TaskFinish DATETIME)
1 to many relationship between Events and EventTasks, etc.
When the dates in the Event table are changed, the EventTask dates need to be changed as well – not difficult with supplied date functions, but date manipulation is always just a bit tricky.
I was wondering if it might be better to replace the TaskStart DATETIME and TaskFinish DATETIME with two INTS: one for Event.Start offset (mins different to Event.Start) and a Duration.
This way date updates become much more robust, as only a single row needs an update.
(I stipulate that this only applies where the EventTask dates are absolutely dependent on the Event dates)
Yes, that sounds entirely reasonable to me. The main downside would be that in order to find the actual times of EventTasks, you have to perform calculations. That will slow down anything returning the times, and in particular will hurt queries involving EventTask times in the filter – e.g. “find me all tasks which occur between times X and Y.” Those could previously have used an index, but won’t be able to any more.