Re: unknown symbol in ER diagram
From: onedaywhen (jamiecollins_at_xsmail.com)
Date: 02/22/05
- Next message: Elizabeth: "Change all lower case entries to upper case"
- Previous message: Roger Carlson: "Re: How do I change table permissions in Access?"
- In reply to: onedaywhen: "Re: unknown symbol in ER diagram"
- Next in thread: Tim Ferguson: "Re: unknown symbol in ER diagram"
- Reply: Tim Ferguson: "Re: unknown symbol in ER diagram"
- Messages sorted by: [ date ] [ thread ]
Date: 22 Feb 2005 06:34:17 -0800
> Tim Ferguson wrote:
> > Ideally, there should be a rule to prevent
> > any Policy existing in more than one subtype table, but AFAIK this
is
> not a
> > feature of any existing RDBMS
>
> Do a google groups search for the exact phrase "CREATE TABLE SUV" for
a
> Joe Celko post on the subject. <Quote> use a compound candidate
> key (vin, vehicle_type) and a constraint in each sub-class table to
> assure that the vehicle_type is locked and agrees with the Vehicles
> table </Quote>.
Thinking about this some more, if you don't like the vehicle_type style
lockdown, I think you could use CHECK constraints to do the same thing.
The following is quick/dirty and off the top of my head (there must be
a more efficient way than NOT IN):
CREATE TABLE Main (
main_ID INTEGER NOT NULL PRIMARY KEY
)
;
CREATE TABLE Sub1 (
main_ID INTEGER NOT NULL PRIMARY KEY,
CONSTRAINT fk__sub1 FOREIGN KEY (main_ID)
REFERENCES Main (main_ID)
)
;
CREATE TABLE Sub2 (
main_ID INTEGER NOT NULL PRIMARY KEY,
CONSTRAINT fk__sub2 FOREIGN KEY (main_ID)
REFERENCES Main (main_ID)
)
;
CREATE TABLE Sub3 (
main_ID INTEGER NOT NULL PRIMARY KEY,
CONSTRAINT fk__sub3 FOREIGN KEY (main_ID)
REFERENCES Main (main_ID)
)
;
ALTER TABLE Sub1 ADD CONSTRAINT ch__sub1
CHECK (
main_ID NOT IN (SELECT main_ID FROM Sub2)
AND main_ID NOT IN (SELECT main_ID FROM Sub3)
)
;
ALTER TABLE Sub2 ADD CONSTRAINT ch__sub2
CHECK (
main_ID NOT IN (SELECT main_ID FROM Sub1)
AND main_ID NOT IN (SELECT main_ID FROM Sub3)
)
;
ALTER TABLE Sub3 ADD CONSTRAINT ch__sub3
CHECK (
main_ID NOT IN (SELECT main_ID FROM Sub1)
AND main_ID NOT IN (SELECT main_ID FROM Sub2)
)
;
Jamie.
--
- Next message: Elizabeth: "Change all lower case entries to upper case"
- Previous message: Roger Carlson: "Re: How do I change table permissions in Access?"
- In reply to: onedaywhen: "Re: unknown symbol in ER diagram"
- Next in thread: Tim Ferguson: "Re: unknown symbol in ER diagram"
- Reply: Tim Ferguson: "Re: unknown symbol in ER diagram"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|