Skip site navigation (1) Skip section navigation (2)

Re: foreign key

From: "Stephan Szabo" <sszabo(at)bigpanda(dot)com>
To: "Arindam Guha" <arindam_guha(at)hotmail(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: foreign key
Date: 2000-04-13 11:18:36
Message-ID: 016a01bfa53a$31d82bc0$e2311a26@bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-sql
How did you define the foreign key constraint on the tables?
Also, are you sure that on update of child table it is saying
that the parent record exists instead of doesn't (see below)?

I would guess from the behavior you are seeing that you 
did not define any actions for update or delete.  In that case,
updates to the master will fail if any child references that row,
and updates to the child will fail if the master you are updating
to does not exist.  

I'd say that you probably want to define the cascade action
for update, so that changes to the master table will propogate 
into the child table.  To do this, you need to say "on update cascade"
in the definition of the constraint (for example:
 masterid int references master(id) on update cascade
)

And right now, the only way to permanently delete a foreign key 
constraint is to remove the triggers.  You need to find the
rows in pg_trigger that are associated with the constraint and
drop those triggers.  There should be 3 triggers I believe.

----- Original Message ----- 
From: Arindam Guha <arindam_guha(at)hotmail(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Wednesday, April 12, 2000 7:03 PM
Subject: [SQL] foreign key


> How to avoid  updation anomaly like this :
> 
> While trying to update in the parent table it says child record exists
> and
> while trying to update in the child table it says parent record exists
> 
> I am trying to update the foreign key column in both the tables ?
> 
> Also how to delete a foreign key constraint ?
> 
> Thanks
> Arindam
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 


In response to

pgsql-sql by date

Next:From: Andy LewisDate: 2000-04-13 14:06:09
Subject: Re: Subtracting from a date
Previous:From: Moray McConnachieDate: 2000-04-13 09:28:26
Subject: Re: Subtracting from a date

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group