Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E72AD9FB41D for ; Mon, 23 Oct 2006 12:41:37 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 05919-03 for ; Mon, 23 Oct 2006 12:41:18 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31812.mail.mud.yahoo.com (web31812.mail.mud.yahoo.com [68.142.207.75]) by postgresql.org (Postfix) with SMTP id 9629F9FB41E for ; Mon, 23 Oct 2006 12:41:17 -0300 (ADT) Received: (qmail 86162 invoked by uid 60001); 23 Oct 2006 15:41:16 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=43DKOcitd8JHSbcY3DSDdovUf07yrdyE5ZZPtJLC/mFuuihtsfcJkhX09wLP/eMYLFjOGCaw3GS12DPoBtDUdF5ThO0fXSayuFTfrC2lcSIGoklDYM3ft9bHpRmIeT2I82EnpoMghUaHxjotIl46UT8ymRscbJRL+CJXlDLyNQA= ; Message-ID: <20061023154116.86160.qmail@web31812.mail.mud.yahoo.com> Received: from [12.177.97.50] by web31812.mail.mud.yahoo.com via HTTP; Mon, 23 Oct 2006 08:41:16 PDT Date: Mon, 23 Oct 2006 08:41:16 -0700 (PDT) From: Richard Broersma Jr Subject: Re: delete on cascade To: Luca Ferrari , pgsql-sql@postgresql.org In-Reply-To: <200610231049.16507.fluca1978@infinito.it> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.191 tagged_above=0 required=5 tests=AWL, SPF_HELO_SOFTFAIL, SPF_SOFTFAIL X-Spam-Level: *** X-Archive-Number: 200610/204 X-Sequence-Number: 26593 > Hi all, > I guess this is an already asked question, but I didn't found an answer, so > apologize me. Imagine I've got two tables: > skill(id,description) // primary key => id > family(id,description) // primary key => id > and I want to associate skills to families: > ass_sf(id_skill,id_family) // appropriate foreign keys > > Tables are already created and the database is running. Now I'd like to > implement a delete cascade, thus when I delete a skill also its association > with the family must be deleted. I gues I should have declared the skill > table as follows: > CREATE TABLE skill > ( > id varchar(20) on delete cascade, > description varchar(50), > primary key(id) > ); > > right? The problem is: how can I alter the table to add the column constraint > now, without redeclaring the table? > Thanks very much for helping me. This link has one line that is very similar to what you want to do. You will probably have to start a transaction, drop the foriegn key contraint and then add a new foriegn key contraint with the on drop cascade . http://archives.postgresql.org/pgsql-general/2006-10/msg00467.php Regards, Richard Broersma Jr.