Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: SQL Database design question

Re: SQL Database design question

From: -CELKO- <jcelko212_at_earthlink.net>
Date: 29 Jan 2005 14:58:18 -0800
Message-ID: <1107039498.465952.279370@c13g2000cwb.googlegroups.com>


>> From Dan's original post "they [the employees] should be ab­le to
work at more than one branch". The JobAssignments table would the­refore represents a many-to-many relationship. That was my interpre­tation anyway. <<

My interpre­tation 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 - 16:58:18 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US