Re: delete on cascade

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: delete on cascade
Date: 2006-10-23 09:00:20
Message-ID: 200610231200.20932.achill@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Στις Δευτέρα 23 Οκτώβριος 2006 11:49, ο/η Luca Ferrari έγραψε:
> 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

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
ass_sf table and define it like

CREATE TABLE ass_sf (
.....
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

--
Achilleas Mantzios

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Luca Ferrari 2006-10-23 09:50:18 Re: delete on cascade
Previous Message Luca Ferrari 2006-10-23 08:49:16 delete on cascade