Florence said:
I have two fields "start" and "end" but if I create an index to not
allow duplicate on the index (car, date, start, and end) it doesn't count the
times in between start and end
<quote>
There are four kinds of duplicates [in a time-valid state tables]...
[1] Two rows are 'value-equivalent' is the values of their
non-TIMESTAMP columns are identical. Value equivalence is a weak form
of duplication [for a time-valid state table]...
[2] Two rows are 'sequenced duplicates' if they are duplicates at some
instant...the values of the non-TIMESTAMP columns...are value
equivalent and the periods of validity overlap... As with primary keys,
the adjective 'sequenced' means that the operation or constraint is
applied independently at every point in time....
[3] A variant of sequenced duplicate is a 'current duplicate', in which
there are duplicate rows in the current state [current instant]...
Interestingly, whether a table contains current duplicate rows can
change over time, even if no modifications are made to the table...
[4] Two rows are 'nonsequenced duplicates' if the values of all columns
are identical... This adjective emphasizes that the property (in this
case, duplicates) is not applied independently at each point in time,
but rather is applied to the table as a whole, ignoring its temporal
nature.
</quote>
Snodgrass, 'Developing Time-Oriented Database Applications in SQL'
(
http://www.cs.arizona.edu/~rts/tdbbook.pdf), 5.5 P121-122 (PDF
P145-146)
You can use a Jet 4.0 table-level CHECK constraint to ensure there are
no overlapping periods. I posted an example recently (before I'd read
the above book!), using salary history, which you should be able to
adapt:
http://groups.google.com/group/microsoft.public.access.forms/msg/04c3f233ba3336cc
ALTER TABLE EarningsHistory ADD
CONSTRAINT earnings_history__no_overlapping_periods
CHECK (0 = (
SELECT *
FROM EarningsHistory, EarningsHistory AS E2
WHERE EarningsHistory.employee_nbr = E2.employee_nbr
AND EarningsHistory.start_date < E2.start_date
AND
(
E2.start_date
< IIF(EarningsHistory.end_date IS NULL, NOW(),
EarningsHistory.end_date)
OR IIF(E2.end_date IS NULL,
NOW(),
E2.end_date) < IIF(EarningsHistory.end_date IS NULL,
NOW(), EarningsHistory.end_date)
)
)
);
I posted a challenge yesterday to see if anyone could implement the
primary key without a table-level CHECK constraint, as yet no takers...
Jamie.
--