foreign keys constraints, depending on each other
| От | zilch@home.se | 
|---|---|
| Тема | foreign keys constraints, depending on each other | 
| Дата | |
| Msg-id | 20010610213122.A29410@loony обсуждение исходный текст | 
| Ответы | Re: foreign keys constraints, depending on each other Re: foreign keys constraints, depending on each other Re: foreign keys constraints, depending on each other | 
| Список | pgsql-general | 
I was just creating this little database for demonstrating the use of
foreign keys constraints.
I was about the create 3 tables, namely mother, father and child. Mother has
a foreign key pointing at father ( id ), and father has a foreign key
pointing at mother ( id ). Child has one pointer to mother ( id ) and one
pointer to father ( id ). How can I prevent the error message from occurring?
Ofcourse I see the problem here... just by taking away the references
keyword from the mother table takes away the problem completely.
---
DROP SEQUENCE mother_id_seq;
DROP SEQUENCE father_id_seq;
DROP SEQUENCE child_id_seq;
DROP TABLE mother;
DROP TABLE father;
DROP TABLE child;
CREATE TABLE mother (
       id           SERIAL,
       fatherID     INT4 NOT NULL REFERENCES father ( id ) ON DELETE CASCADE,
       name         TEXT,
       UNIQUE ( fatherID )
);
CREATE TABLE father (
       id           SERIAL,
       motherID     INT4 NOT NULL REFERENCES mother ( id ) ON DELETE CASCADE,
       name         TEXT,
       UNIQUE ( motherID )
);
CREATE TABLE child (
       id          SERIAL,
       motherID    INT4 NOT NULL REFERENCES mother ( id ) ON DELETE CASCADE,
       fatherID    INT4 NOT NULL REFERENCES father ( id ) ON DELETE CASCADE,
       name        TEXT
);
---
Thanks
Daniel Akerud
		
	В списке pgsql-general по дате отправления: