Received: from smtp011.mail.yahoo.com (smtp011.mail.yahoo.com [216.136.173.31]) by postgresql.org (8.11.3/8.11.4) with SMTP id f7NDjgP56167 for ; Thu, 23 Aug 2001 09:45:42 -0400 (EDT) (envelope-from janwieck@yahoo.com) Received: from jupiter.us.greatbridge.com (65.196.69.55) by smtp.mail.vip.sc5.yahoo.com with SMTP; 23 Aug 2001 13:45:35 -0000 X-Apparently-From: Received: (from wieck@localhost) by jupiter.us.greatbridge.com (8.11.2/8.11.2) id f7NDtb301413; Thu, 23 Aug 2001 09:55:37 -0400 From: Jan Wieck Message-Id: <200108231355.f7NDtb301413@jupiter.us.greatbridge.com> Subject: Re: protected ON DELETE CASCADE In-Reply-To: <3B842BA3.D7E3930D@efone.com> from Murray Hobbs at "Aug 23, 2001 10:01:07 am" To: Murray Hobbs Date: Thu, 23 Aug 2001 09:55:37 -0400 (EDT) CC: pgsql-sql@postgresql.org, pgsql-novice@postgresql.org, pgsql-general@postgresql.org X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200108/716 X-Sequence-Number: 14113 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