dbTalk Databases Forums  

Re: Modifying an existing constraint?

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: Modifying an existing constraint? in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: Modifying an existing constraint? - 06-04-2004 , 06:14 PM







On Fri, 4 Jun 2004, Lynna Landstreet wrote:

Quote:
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.


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
  #2  
Old   
Lynna Landstreet
 
Posts: n/a

Default Re: ON DELETE CASCADE (was: Modifying an existing - 06-05-2004 , 12:35 PM






on 6/4/04 7:14 PM, Stephan Szabo at sszabo (AT) megazone (DOT) bigpanda.com wrote:

Quote:
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


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #3  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: ON DELETE CASCADE (was: Modifying an existing - 06-06-2004 , 01:54 AM




On Sat, 5 Jun 2004, Lynna Landstreet wrote:

Quote:
on 6/4/04 7:14 PM, Stephan Szabo at sszabo (AT) megazone (DOT) bigpanda.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?
Yep.

Quote:
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?
Correct. If there's any similar behavior you do want (for example not
allowing exhibitions with no artists or some such) you'll pretty much need
to do custom triggers.


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.