pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan Wieck <JanWieck@Yahoo.com>
To: Murray Hobbs <murray@efone.com>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-novice@postgresql.org
Cc: pgsql-general@postgresql.org
Subject: Re: protected ON DELETE CASCADE
Date: Thu, 23 Aug 2001 09:55:37 -0400 (EDT)
Message-ID: <200108231355.f7NDtb301413@jupiter.us.greatbridge.com> (raw)
In-Reply-To: <3B842BA3.D7E3930D@efone.com>

Murray Hobbs wrote:
>
> here's my problem
>
> i have tables A, B, C, D
>
> A <- B
> A <- C <- D
>
> i want to maintain integrity so that if A is deleted from then so is
> anything referencing from B and C - no problem ON DELETE CASCADE
>
> but if there are any D's that point back to A (through composite key in
> C) i don't want the delete to go ahead - at all - i want an error
> message and condition

    So  B  and  C  reference  A  with  ON DELETE CASCADE, while D
    references C without it. The default behaviour of  a  foreign
    key  constraint  is  ON  DELETE  NO ACTION, which confusingly
    enough aborts the transaction (it's defined that way  in  the
    SQL  standard,  don't  ask  me why they called it NO ACTION).
    Thus a deletion from A will cascaded delete from C, but  then
    the  constraint  on  D  will  abort  the  transaction if this
    automatic delete from C would orphan a reference from D.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




view thread (7+ messages)  latest in thread

Message-ID: <200108231355.f7NDtb301413@jupiter.us.greatbridge.com>
Permalink:  ../200108231355.f7NDtb301413@jupiter.us.greatbridge.com/
Also on:    postgresql.org/message-id/200108231355.f7NDtb301413@jupiter.us.greatbridge.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: JanWieck@Yahoo.com, murray@efone.com, pgsql-novice@postgresql.org, pgsql-general@postgresql.org
  Subject: Re: protected ON DELETE CASCADE
  In-Reply-To: <200108231355.f7NDtb301413@jupiter.us.greatbridge.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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