Tim said:
I would be making a compound primary key out of the (UserID, SomethingDate)
pair.
Me too.
Just for good luck, I would pack the date into a Long Integer field,
partly because it's probably physically quicker and neater, more because it
logically removes the possibility of confounding by stray time values
creeping in.
Did you know that you can put a Long Date format (or whatever) on a long
integer field?
If I have temporal data then the chances are I want to operate on them
using temporal functions. Formatting a different data type in
individual front end applications isn't going to do it for me if I'm
always having to cast as DATETIME in my SQL code
Instead, I'd strongly type as DATETIME and use CHECKs to ensure my
start date and end dates have the minimum and maximum possible time
values respectively e.g.
CREATE TABLE Test (
key_col INTEGER NOT NULL,
start_date DATETIME DEFAULT DATE() NOT NULL,
CONSTRAINT start_date_value_valid CHECK
(
HOUR(start_date) = 0
AND MINUTE(start_date) = 0
AND SECOND(start_date) = 0
),
end_date DATETIME,
CONSTRAINT end_date_value_valid CHECK
(
HOUR(end_date) = 23
AND MINUTE(end_date) = 59
AND SECOND(end_date) = 59
),
PRIMARY KEY (start_date, key_col)
);
The above wouldn't work for a Jet 3.51 database, though, but then I
wouldn't use one of those either ;-)