Subject Re: [ib-support] Creating Foreign keys
Author Martijn Tonies
> I have table MASS_PERSONS which has foreign key to MASSGROUPS table.
> ALTER TABLE MASS_PERSONS_LV ADD CONSTRAINT FK_MASSPERS FOREIGN KEY (GR_ID)
REFERENCES MASSGROUPS(ID) ON UPDATE CASCADE ON DELETE
>
> Now I wanted to add another table (MASS_PERSONS_LV) and create similar
foreign key, but I get error "Object MASSGROUPS is in use".
> Is it not possible to have 2 tables, both having foreign key linked to the
same table?
>
>
> CREATE TABLE MASS_PERSONS_LV (
> GR_ID INTEGER NOT NULL,
> NAME VARCHAR(30) CHARACTER SET WIN1252,
> ACCOUNT VARCHAR(16) CHARACTER SET WIN1252,
> REGNO VARCHAR(15) CHARACTER SET WIN1252,
> BANK VARCHAR(12) CHARACTER SET WIN1252,
> AMOUNT NUMERIC(15,2)
> );

No COMMIT? Hmmm ... that means the table MASS_PERSONS_LV
isn't really existing yet ... Sounds like a good reason why the ALTER fails
:)

> ALTER TABLE MASS_PERSONS_LV ADD CONSTRAINT FK_MASSPERS_LV FOREIGN KEY
(GR_ID) REFERENCES MASSGROUPS(ID) ON UPDATE CASCADE ON DELETE CASCADE;
>
>

With regards,

Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com

See you at the First European Firebird Conference in May in Fulda, Germany
http://www.firebird-conference.com