Re: Database Design - Relationsships
Date: 20 Sep 2002 08:49:41 -0700
Message-ID: <c0d87ec0.0209200749.4a6452d9_at_posting.google.com>
create a dummy project number, say zero, for this situation. Otherwise, you cannot track anyone's time. It is not a NULL becuase you know whqt they were doing, so there is no missing value.
>> I want to make sure if the user picks a project it is a project
that has the same customerid as the entered customerid in other words:
a Time log entry should not be able to have one customerid and a
project with another customerid. <<
The goal of normalization is to avoid storing redundant data, like you
are trying to do. Chris Date has a few papers on this topic you might
want to look at. I'd get rid of the timelog as redundant and go with
something like this:
CREATE TABLE Customers
CREATE TABLE Employees
CREATE TABLE Projects
CREATE TABLE ProjectAssignments
(cust_id INTEGER NOT NULL PRIMARY KEY,
...);
(emp_nbr INTEGER NOT NULL PRIMARY KEY,
...);
(project_nbr INTEGER NOT NULL PRIMARY KEY,
proj_description VARCHAR(30) NOT NULL,
...);
INSERT INTO Projects VALUES (0, 'non-project work', ...);
(cust_id INTEGER NOT NULL
REFERENCES Customers (cust_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
project_nbr INTEGER NOT NULL DEFAULT 0 -- dummy project nbr
REFERENCES Projects(project_nbr)
ON UPDATE CASCADE
ON DELETE CASCADE,
emp_nbr INTEGER NOT NULL
REFERENCES Employees(emp_nbr)
ON UPDATE CASCADE,
PRIMARY KEY (cust_id, project_nbr, emp_nbr));
The DEFAULT will put in the dummy project number for you. Received on Fri Sep 20 2002 - 17:49:41 CEST