Re: SQL Database design question
Date: 29 Jan 2005 14:58:18 -0800
Message-ID: <1107039498.465952.279370_at_c13g2000cwb.googlegroups.com>
>> From Dan's original post "they [the employees] should be able to
work at more than one branch". The JobAssignments table would
therefore represents a many-to-many relationship. That was my
interpretation anyway. <<
My interpretation was that an employee is always at one branch, which makes physical sense, but we can move him by updating his assignment. If we want to have him in multiple branches, we could change the keys on JobAssignments and use
CREATE TABLE JobAssignments
(ssn CHAR(9) NOT NULL
REFERENCES Personnel (ssn)
ON UPDATE CASCADE
ON DELETE CASCADE,
branch_id INTEGER NOT NULL
REFERENCES Branches (branch_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (ssn, branch_id));
Then use a DISTINCT in the assertion.
CREATE ASSERTION Everyone_assigned_at_least_once CHECK ((SELECT COUNT(DISTINCT ssn) FROM JobAssignments) = (SELECT COUNT(ssn) FROM Personnel)); Received on Sat Jan 29 2005 - 23:58:18 CET
