| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Schema / SQL advise
>> Let's try some real DDL
CREATE TABLE Teams
(team_id INTEGER NOT NULL PRIMARY KEY,
name CHAR(25) NOT NULL,
description VARCHAR(250) NOT NULL,
... );
CREATE TABLE Personnel
(emp_id INTEGER NOT NULL PRIMARY KEY,
name CHAR(25) NOT NULL,
phone CHAR(10) NOT NULL,
email VARCHAR(64) NOT NULL CHECK (email LIKE '%@%'),
... );
>>
Rules:
<<
Good specs!!
>> Option A ... <<
There are no "fields"; tables have columnds and there a huge difference. Not thinking about it is probalby why you made the mistake in both of the design options you gave of putting a non-1NF comma delimited list of employee identifiers.
CREATE TABLE TeamAssignments
(team_id INTEGER NOT NULL
REFERENCES Teams(team_id)
ON DELETE CASCADE
ON UPDATE CASCADE,
emp_id INTEGER NOT NULL
REFERENCES Personnel(emp_id)
ON DELETE CASCADE
ON UPDATE CASCADE,
role CHAR(1) NOT NULL DEFAULT 'L'
CHECK role IN ('L', 'M'), -- l= leader, m= member
CONSTRAINT Teams_have_one_leader
(SELECT *
FROM TeamAssignments
WHERE role = 'L'
GROUP BY team_id
HAVING COUNT(role) > 1));
That constraint is legal SQL-92, but it is not implemented in all SQL products.
Your queries can be done easily with TeamAssignment. Received on Sat Jul 21 2001 - 18:32:07 CDT
![]() |
![]() |