[quoted text, click to view] "Naomi Morton" <dopey_delete@remove.iol.ie> wrote in message
news:1069954180.280897@emeairlvalid.ie.baltimore.com...
> Hey
>
> I need to store something a little different in a DB and I was hoping one of
> you guys might be able to help me.
>
> Basically it represents a 'world'. I have an initial state and then I get
> info like this...
>
> 27/11/03 17:21 Mary is born
> 27/11/03 17:21 Dave is born
> 27/11/03 17:22 Sean is born
> 27/11/03 17:23 Peter dies
> 27/11/03 17:23 Fred is born
Perhaps something like this:
CREATE TABLE Worlds
(
world_id INT NOT NULL PRIMARY KEY
)
CREATE TABLE Persons
(
world_id INT NOT NULL REFERENCES Worlds (world_id),
person_name VARCHAR(25) NOT NULL,
birth_datetime DATETIME NOT NULL,
death_datetime DATETIME NULL, -- NULL if still alive
CHECK (death_datetime >= birth_datetime),
PRIMARY KEY (world_id, birth_datetime, person_name) -- simplification
)
[quoted text, click to view] > I need to be able to run querys like this...
>
> How many people are alive at 27/11/03 17:22
DECLARE @alive_at_datetime DATETIME
SET @alive_at_datetime = '20031127 17:22'
SELECT world_id, COUNT(*) AS alive_at_datetime
FROM Persons
WHERE birth_datetime <= @alive_at_datetime AND
(death_datetime IS NULL OR death_datetime > @alive_at_datetime)
GROUP BY world_id
[quoted text, click to view] > Who was born between 27/11/03 17:22 and 27/11/03 17:23
DECLARE @start_datetime DATETIME, @end_datetime DATETIME
SET @start_datetime = '20031127 17:22'
SET @end_datetime = '20031127 17:23'
SELECT world_id, person_name, birth_datetime
FROM Persons
WHERE birth_datetime BETWEEN @start_datetime AND @end_datetime
[quoted text, click to view] > etc.
>
> Problem is, I'm going to have hundres of 'world's each with thousands of
> entrys.
Millions of rows should not present a problem at all.
Regards,
jag
[quoted text, click to view] > All help is appreciated :)
>
> Tnx
>
> Naomi