Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 4D7739FB379 for ; Mon, 23 Oct 2006 06:01:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 36390-09 for ; Mon, 23 Oct 2006 09:00:26 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by postgresql.org (Postfix) with ESMTP id EF88D9FA3C0 for ; Mon, 23 Oct 2006 06:00:24 -0300 (ADT) Received: from host3.dynacom.ondsl.gr ([62.103.35.211] helo=ip216.internal.net) by matrix.gatewaynet.com with esmtp (Exim 4.62) (envelope-from ) id 1GbvfR-0000My-Cm for pgsql-sql@postgresql.org; Mon, 23 Oct 2006 12:00:21 +0300 From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: pgsql-sql@postgresql.org Subject: Re: delete on cascade Date: Mon, 23 Oct 2006 12:00:20 +0300 User-Agent: KMail/1.9.3 References: <200610231049.16507.fluca1978@infinito.it> In-Reply-To: <200610231049.16507.fluca1978@infinito.it> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200610231200.20932.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/200 X-Sequence-Number: 26589 =D3=F4=E9=F2 =C4=E5=F5=F4=DD=F1=E1 23 =CF=EA=F4=FE=E2=F1=E9=EF=F2 2006 11:4= 9, =EF/=E7 Luca Ferrari =DD=E3=F1=E1=F8=E5: > 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 =3D> id > family(id,description) // primary key =3D> 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 associati= on > 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 not right!!! ON DELETE CASCADE is specified in FOREIGN KEY contsraints. So that would be in ass_sf table. If you find ALTER TABLE ass_sf command hard to run, then drob your=20 ass_sf table and define it like CREATE TABLE ass_sf ( =2E.... skill_id INT REFERENCES skill(id) ON DELETE CASCADE, familly_id INT REFERENCES family(id) ON DELETE CASCADE ); The above causes cascade deletes not only on skills but on families also. > constraint now, without redeclaring the table? > Thanks very much for helping me. > Luca > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match =2D-=20 Achilleas Mantzios