1 to many relationships

From: Dennis Gearon <gearond(at)cvc(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: 1 to many relationships
Date: 2003-02-23 05:16:29
Message-ID: 3E58592D.51713CB1@cvc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If I have a child table and a parent table like so:

---BEGIN TABLE DEFS---------------------------------------------
create table parents(
PriKey serial
);
add primary constraint to PriKey;

create table child(
parent INT4 NOT NULL
);
add foreign key constraint parent refs parent.PriKey ON DELETE CASCADE;

---BEGIN RELATIONSHIP DEF----------------------------------------
They are supposed to have the following relationship:

parent(1T1)<------->(1TM)children

textually explained as 'One parent has many children and must have at
least one in order to exist, while a child must have one and only one
parent in order to exist')

---BEGIN PROBLEM DEF / QUESTION --------=------------------------
For the 1T1 side of the relationship:
the table defs will automatically cause the children to be caught or
killed in the event that their parents disappear, no prob.

For the 1TM side of the relationship:
I don't see anything in the docs that says the PARENT will be
sacrificed if their children don't survive or disappear, and I don't
even know if there exists in any database the table definition option to
enforce this.

How is this done on different DB's? On Postgres?

---BEGIN GUESS---------------------------------------------------
Triggers?

--

Carpe Dancem ;-)
-----------------------------------------------------------------
Remember your friends while they are alive
-----------------------------------------------------------------
Sincerely, Dennis Gearon

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Shridhar Daithankar<shridhar_daithankar@persistent.co.in> 2003-02-23 07:01:43 Re: What filesystem?
Previous Message Tom Lane 2003-02-23 05:14:27 Re: Strange error (Socket command option unknown)