pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ad hoc referential integrity
2+ messages / 2 participants
[nested] [flat]

* ad hoc referential integrity
@ 2003-07-15 04:39  Matt Tenenbaum <matt@tty1.org>
  0 siblings, 1 reply; 2+ messages in thread

From: Matt Tenenbaum @ 2003-07-15 04:39 UTC (permalink / raw)
  To: pgsql-sql

At the outset I hope that this is the right place to ask this question 
(also, I hope the question isn't a foolish one).

Say I created a couple tables A and B, where A contains a column p 
which B references as a foreign key. Further say that, when I created 
these tables, I meant to specify 'on delete cascade' for p in the 
definition of B but didn't. What's the proper way to ensure both the 
integrity of the tables and that, when I delete rows from A, the 
corresponding rows from B are removed as well? (In particular, is there 
a shorter way than dropping the table and recreating it? Are rules the 
answer?)

Again, I hope this is the right place to answer this question; I guess 
I'm not 'new' to SQL, but I'm still a bit rough around the edges, so 
trying to find the answer on my own has been a bit slow-going.

Thanks for any help.
-matt




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: ad hoc referential integrity
@ 2003-07-15 04:48  Stephan Szabo <sszabo@megazone.bigpanda.com>
  parent: Matt Tenenbaum <matt@tty1.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Stephan Szabo @ 2003-07-15 04:48 UTC (permalink / raw)
  To: Matt Tenenbaum <matt@tty1.org>; +Cc: pgsql-sql

On Tue, 15 Jul 2003, Matt Tenenbaum wrote:

> Say I created a couple tables A and B, where A contains a column p
> which B references as a foreign key. Further say that, when I created
> these tables, I meant to specify 'on delete cascade' for p in the
> definition of B but didn't. What's the proper way to ensure both the
> integrity of the tables and that, when I delete rows from A, the
> corresponding rows from B are removed as well? (In particular, is there
> a shorter way than dropping the table and recreating it? Are rules the
> answer?)

If I'm understanding what you want, I'd suggest dropping the constraint
and re-adding it with the on delete cascade.  If you're on 7.3 or better
you should be able to do this entirely with alter table, before that you
have to do a little more work.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-07-15 04:48 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-07-15 04:39 ad hoc referential integrity Matt Tenenbaum <matt@tty1.org>
2003-07-15 04:48 ` Stephan Szabo <sszabo@megazone.bigpanda.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox