From: | Lynna Landstreet <lynna(at)gallery44(dot)org> |
---|---|
To: | <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: ON DELETE CASCADE (was: Modifying an existing |
Date: | 2004-06-05 17:35:35 |
Message-ID: | BCE77CA7.1379%lynna@gallery44.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
on 6/4/04 7:14 PM, Stephan Szabo at sszabo(at)megazone(dot)bigpanda(dot)com wrote:
> On Fri, 4 Jun 2004, Lynna Landstreet wrote:
>
>> Does anyone know if it's possible to modify an existing table constraint -
>> for example, to add "ON DELETE CASCADE" to an existing foreign key
>> constraint? Or would I have to recreate the table to add that?
>
> You can drop the constraint and add it again with the additional clause
> using ALTER TABLE. One warning is that it will recheck the constraint in
> this case which may make the ALTER slow if there's alot of data.
Cool - tried it, and it worked. Thanks!
Now, just to make sure I'm applying this correctly: ON DELETE CASCADE tells
the table you're applying it to a foreign key within to delete a row if the
corresponding row in another table which the foreign key references is
deleted, right?
So if I have a table of artists, and a table of exhibitions, and a join
table linking them by specifying which artists have appeared in which
exhibitions, and I add ON DELETE CASCADE to both the artist_id and
exhibition_id columns in the join table, then if either an artist or an
exhibition is deleted, any rows in the join table that reference that artist
will be deleted automagically? It won't go one step further and delete the
exhibition or artist it was joining them to, will it?
Just wanting to make sure I'm not setting myself up for disaster here...
Lynna
--
Resource Centre Database Coordinator
Gallery 44
www.gallery44.org
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2004-06-06 06:54:26 | Re: ON DELETE CASCADE (was: Modifying an existing |
Previous Message | Tom Lane | 2004-06-05 04:46:37 | Re: Modifying an existing constraint? |