Re: protected ON DELETE CASCADE - Mailing list pgsql-general

From Jan Wieck
Subject Re: protected ON DELETE CASCADE
Date
Msg-id 200108231355.f7NDtb301413@jupiter.us.greatbridge.com
Whole thread Raw
In response to protected ON DELETE CASCADE  (Murray Hobbs <murray@efone.com>)
List pgsql-general
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


pgsql-general by date:

Previous
From: wsheldah@lexmark.com
Date:
Subject: How do I drop or change a foreign key?
Next
From: "Gregory Wood"
Date:
Subject: Re: protected ON DELETE CASCADE