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

Re: protected ON DELETE CASCADE

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Murray Hobbs <murray(at)efone(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: protected ON DELETE CASCADE
Date: 2001-08-23 13:55:37
Message-ID: 200108231355.f7NDtb301413@jupiter.us.greatbridge.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novicepgsql-sql
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(at)Yahoo(dot)com #



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


In response to

Responses

pgsql-novice by date

Next:From: Gregory WoodDate: 2001-08-23 14:48:19
Subject: Re: protected ON DELETE CASCADE
Previous:From: Oliver ElphickDate: 2001-08-23 13:24:18
Subject: Re: integrity and inherit

pgsql-general by date

Next:From: Jan WieckDate: 2001-08-23 14:09:19
Subject: Re: SELECT FOR UPDATE
Previous:From: Fernando SchapachnikDate: 2001-08-23 13:54:19
Subject: Re: Postgres and special character

pgsql-sql by date

Next:From: Gregory WoodDate: 2001-08-23 14:48:19
Subject: Re: protected ON DELETE CASCADE
Previous:From: Albert ReinerDate: 2001-08-23 12:12:32
Subject: Re: [NOVICE] protected ON DELETE CASCADE

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